Class EnumUtil
A helper class for handling enums
Inheritance
Namespace: ImageVault.Common.Lib
Assembly: ImageVault.Common.dll
Syntax
public static class EnumUtil : Object
Methods
GetDisplayName(Enum)
Gets the DisplayName from the enum
Declaration
public static string GetDisplayName(Enum value)
Parameters
Type | Name | Description |
---|---|---|
System.Enum | value | The System.Enum value to get the DisplayName from |
Returns
Type | Description |
---|---|
System.String | The displayName of the enum value |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If the enum misses the System.ComponentModel.DisplayNameAttribute |
GetEnumInfo(Enum)
Gets the System.Reflection.FieldInfo for the supplied enum value
Declaration
public static FieldInfo GetEnumInfo(Enum value)
Parameters
Type | Name | Description |
---|---|---|
System.Enum | value | The System.Enum to get the info for |
Returns
Type | Description |
---|---|
System.Reflection.FieldInfo | The found System.Reflection.FieldInfo |
Parse(Type, String)
Parses the supplied string as the supplied enum type
Declaration
public static object Parse(Type type, string stringToParse)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type of enum to parse as |
System.String | stringToParse | The string to parse |
Returns
Type | Description |
---|---|
System.Object | The parsed enum value |
Remarks
Also supports flag enums with | separating the different values
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If |
ParseValidEnum(Type, String)
Parses the supplied enum value
Declaration
public static object ParseValidEnum(Type type, string value)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type of enum to parse |
System.String | value | The string value of the enum |
Returns
Type | Description |
---|---|
System.Object | The found enum value or null if no matchin enum was found. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If |
ParseValidEnum(Type, String, Object)
Parses the supplied enum value
Declaration
public static object ParseValidEnum(Type type, string value, object defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type of enum to parse |
System.String | value | The string value of the enum |
System.Object | defaultValue | The value to return if parsing was not successful |
Returns
Type | Description |
---|---|
System.Object | The found enum value or null if no matchin enum was found. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If |
ToString(Object)
Returns a System.String that represents the supplied enumValue.
Declaration
public static string ToString(object enumValue)
Parameters
Type | Name | Description |
---|---|---|
System.Object | enumValue | The enum value to parse |
Returns
Type | Description |
---|---|
System.String | A System.String that represents the supplied |
Remarks
Flag values are separated by |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If |