You should enable option strict in Outlook ;-)
: public shared function GetDescription (value as Enum)
Public Shared Function GetDescription(ByVal value As Enum) As String
..
..
..
Return IIf(attributes.Length > 0, attributes(0).Description,
value.ToString).ToString
End Function
: End sub
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"Chaos, Panic, Disorder, my work here is done"
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
:
: "Tariq Ahmad" <ta*********@hotmail.com> wrote in message
: news:us****************@TK2MSFTNGP10.phx.gbl...
: > got this code from codeproject.com, but cant convert it to vb.
: >
: > can u help please? thnx.
: >
: > t.
: >
:
--------------------------------------------------------------------------
: --
: > -------
: >
: > Append a Description attribute to each enum entry:
: >
: > private enum MyColors
: > {
: > [Description("yuk!")] LightGreen = 0x012020,
: > [Description("nice :-)")] VeryDeepPink = 0x123456,
: > [Description("so what")] InvisibleGray = 0x456730,
: > [Description("no comment")] DeepestRed = 0xfafafa,
: > [Description("I give up")] PitchBlack = 0xffffff,
: > }To access the description from code, the following function is called:
: >
: Private Enum MyColors
: <Description("yuk!")> LightGreen = &h012020 ''' I may be wrong in the
: hex
: ....
: End Enum
:
:
:
: > public static string GetDescription(Enum value)
: > {
: > FieldInfo fi= value.GetType().GetField(value.ToString());
: > DescriptionAttribute[] attributes =
: > (DescriptionAttribute[])fi.GetCustomAttributes(
: > typeof(DescriptionAttribute), false);
: > return
: (attributes.Length>0)?attributes[0].Description:value.ToString();
: > }
: >
: public shared function GetDescription (value as Enum)
: dim fi as fieldinfo
: Dim attributes() as descriptionattribute
:
: fi = value.gettype().getfield(value.toString())
: attributes = fi.getcustomattributes(gettype(descriptionattribut e),
: false)
:
: return iif(attributes.length > 0, attributes(0).description,
: value.tostring()
: ''' this part may be wrong, I'm just doing it on the fly but this should
: get you going
: End sub
:
: >
:
: