473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

GetFields not working on enum type (anymore)

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(DescriptionAttrib ute), 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;
}
Nov 16 '05 #1
1 3811
I think there might be something wrong with the project.
I put in a line to get all the names of the enum.
When I tried to watch this value I got an out of scope error.
Stepping through, the code jumped over code for no reason, straight into
the middle of the foreach loop and then exited.

I changed the cofig to release, rebuilt the proj, changed back to debug,
rebuilt and now getnames works.

Very very strange

JB
:(
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matteo Settenvini | last post by:
Mmmh... I was trying some code, and I bumped in a strange behaviour. The following piece of code compiles normally : //////// CODE STARTS ///////////////// #include <iostream> class B {...
4
by: Keith Hill | last post by:
Is there a way to represent a style enum in XML Schema? Say I have a flags enum like so: public enum dayOfWeek { Mon, Tue, Wed, All = Mon | Tue | Wed; }
2
by: DDE | last post by:
Hi, I have defined he following class: public class ContactInfo { public string con_nom; public string con_prenom; public string con_fonction; public string con_email; }
3
by: Trewq | last post by:
Hello you, Problem is that Type.GetFields does not return InnerList from a class that inherits from CollectionBase. I have a class: Public Class MyCollection Inherits...
9
by: Tau | last post by:
for example: enum class SomeEnumType { A1 = 1; A2 = 2; A3 = 3; }; how to write a function like:
12
by: Laurent Deniau | last post by:
If I understand well, an enumeration is only garantee to hold at most an int (6.7.2.2-2). So I would like to know: how to store a long in an enum? enum { p2_31 = 1L << 31 }; // boom how to...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
3
by: Jon Slaughter | last post by:
FieldInfo fields = type.GetFields(); works and returns all public fields, but when I do FieldInfo fields = type.GetFields(BindingFlags.Public); I get nothing!! Whats going on? (again,...
5
by: TS | last post by:
i have tried .GetFields (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ); but it wont get the protected properties declared on the type's base class. How do i get it to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.