Any component has a bunch of properties on it. For example, the WinForms Button control has properties like BackColor, ForeColor, Text, Name, BackgroundImage and so on. When you place a Button on the Form in the VisualStudio designer and look at the generated code, you will find only a subset of the properties are persisted in code. Typically, these are the properties for which you explicitly set a value. What is the mechanism the designer uses to achieve this behavior?
First of all, the object that controls this is the CodeDomSerializer associated with the component. It decides how the component should be persisted to code. Here are some of the rules that the CodeDomSerializer associated with common controls like Button uses (well, more accurately, the serializer leaves the decision to the PropertyDescriptor associated with the property and our implementation of the latter uses these rules):
Further, the designer associated with the component can also play a part in making this decision by “shadowing“ properties or by implementing ShouldSerializeXXX methods.
Not happy with this mechanism? Want to serialize your component in a different way? Sure! All you need to do is write your own Serializer class that derives from CodeDomSerializer and associate it with your component using the DesignerSerializerAttribute.
By the way, Whidbey is not just about cool new controls, layout, configuration, improved visual styles support, better design time experience etc. There are a ton of improvements to the designer infrastructure too, as we mentioned briefly at the PDC:
Some of these new classes are already documented at http://longhorn.msdn.microsoft.com. Look under the System.ComponentModel.* and System.*.Design namespaces.