DefaultValue for Enum not working.

17. February 2012 18:13 by Mrojas in   //  Tags: , , , , ,   //   Comments (0)

Today I was writting a custom control which had a custom property whose type was an EnumType.

I needed the DefaultVAlue attribute so Visual Studio.NET will not serialize the value to the container's code.

Usually in C# you can do something like:

[DefaultValue(TheEnum.TheValue)]
public TheEnum MyProperty
{
get { ... }
set { ... }
}
And that works. Well it does not work in VB.NET
To use an enum value for an Enumeration type in VB.NET you should write something like:
<DefaultValue(GetType(TheEnum), "TheValue")> _
Property MyProperty as TheEnum
   Get
       ...
   End Get
   Set 
        ...
   End Set
End Property
 

Categories