ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Static Public Member Functions | List of all members
ImageResizer.ExtensionMethods.EnumExtensions Class Reference

Extends enumerations by allowing them to define alternate strings with the [EnumString("Alternate Name",true)] attribute, and support it through TryParse and ToPreferredString More...

Static Public Member Functions

static T Parse< T > (T en, string value, T defaultValue)
 Attempts case-insensitive parsing of the specified enum. Returns the specified default value if parsing fails. Supports [EnumString("Alternate Value")] attributes and parses flags. If any segment of a comma-delimited list isn't parsed as either a number or string, defaultValue will be returned. More...
 
static T Parse< T > (T en, string value)
 Attempts case-insensitive parsing of the specified enum. Returns null if parsing failed. Supports [EnumString("Alternate Value")] attributes and parses flags. If any segment of a comma-delimited list isn't parsed as either a number or string, null will be returned. More...
 
static T Parse< T > (string value)
 
static string ToPreferredString (Enum en, bool lowerCase)
 Retuns the string representation for the given enumeration More...
 

Detailed Description

Extends enumerations by allowing them to define alternate strings with the [EnumString("Alternate Name",true)] attribute, and support it through TryParse and ToPreferredString

Definition at line 27 of file Enum.cs.

Member Function Documentation

static T ImageResizer.ExtensionMethods.EnumExtensions.Parse< T > ( en,
string  value,
defaultValue 
)
inlinestatic

Attempts case-insensitive parsing of the specified enum. Returns the specified default value if parsing fails. Supports [EnumString("Alternate Value")] attributes and parses flags. If any segment of a comma-delimited list isn't parsed as either a number or string, defaultValue will be returned.

Parameters
en
value
Returns
Type Constraints
T :struct 
T :IConvertible 

Definition at line 101 of file Enum.cs.

101  : struct, IConvertible {
102  T? val = EnumExtensions.Parse<T>(en, value);
103  return val == null ? defaultValue : val.Value;
104  }
static T ImageResizer.ExtensionMethods.EnumExtensions.Parse< T > ( en,
string  value 
)
inlinestatic

Attempts case-insensitive parsing of the specified enum. Returns null if parsing failed. Supports [EnumString("Alternate Value")] attributes and parses flags. If any segment of a comma-delimited list isn't parsed as either a number or string, null will be returned.

Parameters
en
value
Returns
Type Constraints
T :struct 
T :IConvertible 

Definition at line 113 of file Enum.cs.

113  :struct, IConvertible {
114  return Parse<T>(value);
115  }
static T Parse< T >(T en, string value, T defaultValue)
Attempts case-insensitive parsing of the specified enum. Returns the specified default value if parsi...
Definition: Enum.cs:101
static string ImageResizer.ExtensionMethods.EnumExtensions.ToPreferredString ( Enum  en,
bool  lowerCase 
)
inlinestatic

Retuns the string representation for the given enumeration

Parameters
en
lowerCase
Returns

Definition at line 156 of file Enum.cs.

157  {
158  Type t = en.GetType();
159  bool isFlags = false; //Not supported yet t.IsDefined(typeof(FlagsAttribute), false);
160 
161  Dictionary<Enum,string> d = GetPreferredStrings(t);
162 
163  //Simple path
164  if (!isFlags){
165  string temp;
166  if (!d.TryGetValue(en, out temp)) temp = en.ToString();
167  return lowerCase ? temp.ToLowerInvariant() : temp;
168  }
169  return null;
170  //TODO: loop through keys and use binary comparison to build a comma delimited list
171  }

The documentation for this class was generated from the following file: