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).D escription,
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****@blowgoa ts.com> wrote in message
news:eR******** ******@TK2MSFTN GP10.phx.gbl...
:
: "Tariq Ahmad" <ta*********@ho tmail.com> wrote in message
: news:us******** ********@TK2MSF TNGP10.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("yu k!")] LightGreen = 0x012020,
: > [Description("ni ce :-)")] 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("y uk!")> LightGreen = &h012020 ''' I may be wrong in the
: hex
: ....
: End Enum
:
:
:
: > public static string GetDescription( Enum value)
: > {
: > FieldInfo fi= value.GetType() .GetField(value .ToString());
: > DescriptionAttr ibute[] attributes =
: > (DescriptionAtt ribute[])fi.GetCustomAt tributes(
: > typeof(Descript ionAttribute), false);
: > return
: (attributes.Len gth>0)?attribut es[0].Description:va lue.ToString();
: > }
: >
: public shared function GetDescription (value as Enum)
: dim fi as fieldinfo
: Dim attributes() as descriptionattr ibute
:
: fi = value.gettype() .getfield(value .toString())
: attributes = fi.getcustomatt ributes(gettype (descriptionatt ribute),
: false)
:
: return iif(attributes. length > 0, attributes(0).d escription,
: value.tostring( )
: ''' this part may be wrong, I'm just doing it on the fly but this should
: get you going
: End sub
:
: >
:
: