I know that component-model indicates whether a property has a default value or not, by means of ShouldSerializeValue method of PropertyDescriptor.
The base windows-forms Control
class, has some properties like ForeColor, BackColor and Font, that defaults to the same value of the parent, but I could not find any TypeDescriptor
or PropertyDescriptor
that provides these default values. The Control class does not implement ICustomTypeDescriptor nor has a TypeDescriptionProviderAttribute.
How does the Control class indicates that these properties should be serialized or not? Where does it provide the PropertyDescriptors for these properties??
Thanks!!!
They don't have default values. These properties are "ambient" properties. The Control class detects that a property assignment has occurred for them. If that never happened, it uses the corresponding property from the Parent. Which is nice, it ensures child controls use the same colors and font as their container.
There is a ShouldSerializeForeColor() method in the Control class. It is internal and can't be overridden by user code. Same for the other properties. Have a look-see with Reflector or the .NET Reference Source.
The MSDN Library documents them like this: