How to get a lowercase representation of an enum in C #?

I have the following enumin an ASP.NET MVC application, and I want to use this enumeration as a parameter. For this, I would like to return a string string representation of this enum.

 public enum SortOrder
 {
      Newest = 0,
      Rating = 1, 
      Relevance = 2 
 }

How to get a lowercase representation of an enum in C #? I would like the transfers to also retain their natural representation in the form of tecs.

+5
source share
4 answers

No, there is no extension method to object.

public static string ToLower (this object obj)
{
  return obj.ToString().ToLower();
}
+11
source

Is there a way to get a lowercase string exceptiong: value.ToString (). ToLower ()?

( : newest, rating, relevance...)

, , : http://weblogs.asp.net/grantbarrington/archive/2009/01/19/enumhelper-getting-a-friendly-description-from-an-enum.aspx

+2

Enum.GetNames(...) , . . Enum.Parse, true , .

0

If what the enumeration text displays knows (and uses) the System.ComponentModel namespace, then you can decorate the enumeration with the System.ComponentModel.DescriptionAttribute attribute and enter the bottom registration line.

If you directly get the string value, you can still do it, although the overhead of creating the reflection code may be more than you want to deal with.

NTN, Brian

0
source

All Articles