GetFields not working on enum type (anymore)

From: The Last Gunslinger (jbaroKILLME_at_iprimus.com.au)
Date: 06/23/04


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;
}


Relevant Pages

  • Re: iterating through an array of Strings
    ... You named this variable an array, but didn't declare it as one. ... public static String[] data; ... String doesn't declare an array of Strings, it declares an array of String. ... you are grabbing array elements. ...
    (comp.lang.java.help)
  • Text problem
    ... GetHeaderFromFiles to build up the array. ... LogHead test = new LogHead; ... public static string GetHeaderFromFile ... public static string getDateStart() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Text problem
    ... That is to read a log file into an> array and provide methods to get a random line. ... > LogHead test = new LogHead; ... > public static string GetHeaderFromFile ... > public static string getDateStart() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: byte[] to string conversion ...
    ... public static string ByteArrayToString(byte[] array) ... string str = null; ... ascii.GetChars(array, 0, array.Length, asciiChars, 0); ...
    (microsoft.public.dotnet.languages.csharp)

Quantcast