Click here to Skip to main content
15,928,983 members
Home / Discussions / C#
   

C#

 
AnswerRe: Good class to get file info from JPG ? Pin
Luc Pattyn24-Jan-07 14:58
sitebuilderLuc Pattyn24-Jan-07 14:58 
GeneralRe: Good class to get file info from JPG ? Pin
Marcos Hernandez24-Jan-07 19:37
Marcos Hernandez24-Jan-07 19:37 
GeneralRe: Good class to get file info from JPG ? Pin
Luc Pattyn24-Jan-07 20:23
sitebuilderLuc Pattyn24-Jan-07 20:23 
Questionno white spaces in enum Pin
MVPenn23-Jan-07 6:32
MVPenn23-Jan-07 6:32 
AnswerRe: no white spaces in enum Pin
Dave Kreskowiak23-Jan-07 7:35
mveDave Kreskowiak23-Jan-07 7:35 
GeneralRe: no white spaces in enum Pin
MVPenn23-Jan-07 8:01
MVPenn23-Jan-07 8:01 
GeneralRe: no white spaces in enum Pin
Stefan Troschuetz23-Jan-07 8:26
Stefan Troschuetz23-Jan-07 8:26 
GeneralRe: no white spaces in enum Pin
Pete O'Hanlon23-Jan-07 9:10
mvePete O'Hanlon23-Jan-07 9:10 
Try this:

public static string EnumHelper(Enum value)
{
  // Set the description to the name of the enumeration.
  // That way, if there's no Description attribute, we still
  // have a description to return.
  description = value.ToString();

  MemberInfo[] mi = value.GetType().GetMember(value.ToString());
  if (mi != null && mi.Length > 0)
  {
    object[] att = mi[0].GetCustomAttributes(typeof(Description), false);
    if (att != null  && att.Length > 0)
      description = ((Description)att[0]).Text;
  }
  return description;
}


Then, in your enumeration all you need to do is:

public enum Diseases
{
  [Description("Hepatitis A")]
  HepatitisA,
  Eczema,
}

Then, in your code you will do the following:

string hepA = EnumHelper(Diseases.HepatitisA);


This returns Hepatitis A.

string ex = EnumHelper(Diseases.Eczema);

returns Eczema.

I hope this helps.


the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer

Deja View - the feeling that you've seen this post before.

GeneralRe: no white spaces in enum Pin
Wjousts23-Jan-07 9:11
Wjousts23-Jan-07 9:11 
GeneralRe: no white spaces in enum Pin
Dave Kreskowiak23-Jan-07 12:34
mveDave Kreskowiak23-Jan-07 12:34 
AnswerRe: no white spaces in enum Pin
e-laj23-Jan-07 13:02
e-laj23-Jan-07 13:02 
QuestionRegular Expression for getting links on a web page Pin
Laxmi2723-Jan-07 4:58
Laxmi2723-Jan-07 4:58 
AnswerRe: Regular Expression for getting links on a web page Pin
ednrgc23-Jan-07 5:12
ednrgc23-Jan-07 5:12 
QuestionForms Pin
gigo2k623-Jan-07 4:43
gigo2k623-Jan-07 4:43 
AnswerRe: Forms Pin
bobsugar22223-Jan-07 4:53
bobsugar22223-Jan-07 4:53 
AnswerRe: Forms Pin
Not Active23-Jan-07 4:54
mentorNot Active23-Jan-07 4:54 
GeneralRe: Forms Pin
gigo2k623-Jan-07 6:10
gigo2k623-Jan-07 6:10 
GeneralRe: Forms Pin
Dave Kreskowiak23-Jan-07 6:16
mveDave Kreskowiak23-Jan-07 6:16 
QuestionHow to prevent DataGridView from repainting? Pin
jzb23-Jan-07 3:25
jzb23-Jan-07 3:25 
AnswerRe: How to prevent DataGridView from repainting? Pin
mark_w_23-Jan-07 3:51
mark_w_23-Jan-07 3:51 
AnswerRe: How to prevent DataGridView from repainting? Pin
jesarg23-Jan-07 9:30
jesarg23-Jan-07 9:30 
QuestionDataReader Query Pin
mark_w_23-Jan-07 2:35
mark_w_23-Jan-07 2:35 
AnswerRe: DataReader Query Pin
PIEBALDconsult23-Jan-07 2:42
mvePIEBALDconsult23-Jan-07 2:42 
GeneralRe: DataReader Query Pin
mark_w_23-Jan-07 3:50
mark_w_23-Jan-07 3:50 
QuestionDirectory structure for solution Pin
Syed Muhammad Kamran23-Jan-07 2:24
Syed Muhammad Kamran23-Jan-07 2:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.