Windows Develop Bookmark and Share   
 index > Windows Forms Designer > DefaultValueAttribute for .NET properties
 

DefaultValueAttribute for .NET properties

I know that in order for a property not to be serialized, one should supply a defaultvalue attribute, so if its value is the same as the supplied attribute, VS will not generate additional codes in the InitilizeComponent section.

My question is with regard to the .NET inherited properties like Size, Color, Name, etc.  Since most of these properties does not have defaultvalues with them, they are always serialized in every inherited form eventhough their value is just the same as my base form.

I've seen that most programmers are overriding these properties to be able to include a defaultvalue attribute.  Is this the only way to avoid the unnecessary code generation for such properties?
MigrationUser 1  Monday, August 16, 2004 10:39 PM
These properties do have default values. The serializer will look for this type of data (default value attr or ShouldSerialize func) in the class where the property is declared. So if you change the value of a property in a derived class, and need that to be the new "default" value, yes you must shadow or override the orginal property. You can also use custom designers to supress or change property serialization.
MigrationUser 1  Wednesday, August 18, 2004 9:41 AM
oops, I forgot about that, you're right, they do have default values.  I was just thinking of the best way to customize/change their default values.  I guess I still have to dig in about property serialization using designers...

Thanx a lot...
MigrationUser 1  Thursday, August 19, 2004 5:32 AM

You can use google to search for other answers

Custom Search

More Threads

• Add new method (add code to the class being designed)
• How to use Toolstrip control in C#.Net?
• Borders around ScrollableControl
• Auto change parent in design-time
• Host designer for relations tables diagrams, database modeler - exists an interface?
• Problem of (custom) serialization into the InitializeComponent at Design-time
• xp style or VS controls
• Name Property
• Loading panels too slow
• Estimation for Converting a web Application to Desktop Application