GetFields not working on enum type (anymore)
From: The Last Gunslinger (jbaroKILLME_at_iprimus.com.au)
Date: 06/23/04
- Next message: Peter: "Include .NET Runtime on CD"
- Previous message: joseph.inglis: "Re: ListView"
- Next in thread: The Last Gunslinger: "Re: GetFields not working on enum type (anymore)"
- Reply: The Last Gunslinger: "Re: GetFields not working on enum type (anymore)"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 23 Jun 2004 15:30:57 +1000
I have a method that takes a type that relates to an enum and then gets
all the Description attributes or the name and returns them in a string
array.
This was working until I added the check to see if the field was a
IsSpecialName as I was getting a value__ field I did not want.
Now, GetFields only ever returns a zero length array.
I cannot see what I have done.
The code is below
TIA
--
JB
public static string[] GetEnumDescriptions(System.Type EnumType)
{
string[] ReturnNames = new string[0];
FieldInfo[] Fields = EnumType.GetFields(BindingFlags.CreateInstance |
BindingFlags.Public);
foreach(FieldInfo Field in Fields)
{
if(!Field.IsSpecialName)
{
string[] Temp = new string[ReturnNames.Length + 1];
ReturnNames.CopyTo(Temp, 0);
ReturnNames = Temp;
Object[] Atts =
Field.GetCustomAttributes(typeof(DescriptionAttribute), false);
DescriptionAttribute Att = Atts.Length != 0 ? Atts[0] as
DescriptionAttribute : null;
if(Att != null)
{
ReturnNames[ReturnNames.GetUpperBound(0)] = Att.Description;
}
else
{
ReturnNames[ReturnNames.GetUpperBound(0)] = Field.Name;
}
}
}
return ReturnNames;
}
- Next message: Peter: "Include .NET Runtime on CD"
- Previous message: joseph.inglis: "Re: ListView"
- Next in thread: The Last Gunslinger: "Re: GetFields not working on enum type (anymore)"
- Reply: The Last Gunslinger: "Re: GetFields not working on enum type (anymore)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|