DefaultValue on property with enum value (VB.NET)#
If you have a custom control with a custom property, you can specify a default value for it by using the DefaultValueAttribute. For example: <DefaultValue("")>. This will tell Visual Studio.NET not to serialize the value to the container's code when it is equal to the default value (an empty string in this case). However, if the type of your property is an Enum, you can't just specify the default enum value. You must use an overload to specify the type of the enum and the default value as a string. So use

<DefaultValue(GetType(MyEnum), "MyEnumValue")>

in stead of

<DefaultValue(MyEnum.MyEnumValue)>

Note that both methods work in C#, but only the first one works in VB.NET.
Blog | Programming | .NET | Quirks
Comments are closed.
All content © 2012, Jelle Druyts
On this page

Recent Photos
www.flickr.com
This is a Flickr badge showing public photos from Jelle Druyts. Make your own badge here.
Advertising
Top Picks
Statistics
Total Posts: 350
This Year: 0
This Month: 0
This Week: 0
Comments: 530
Archives
Sitemap
Disclaimer
This is my personal website, not my boss', not my mother's, and certainly not the pope's. My personal opinions may be irrelevant, inaccurate, boring or even plain wrong, I'm sorry if that makes you feel uncomfortable. But then again, you don't have to read them, I just hope you'll find something interesting here now and then. I'll certainly do my best. But if you don't like it, go read the pope's blog. I'm sure it's fascinating.

Powered by:
newtelligence dasBlog 2.0.7226.0

Sign In