Class EnumHelper
Provides methods for working with enumeration values and select lists.
public static class EnumHelper
- Inheritance
-
EnumHelper
- Inherited Members
Methods
GetSelectList(Type)
Gets a list of SelectListItem objects corresponding to enum constants defined in the given type.
public static IList<SelectListItem> GetSelectList(Type type)
Parameters
type
TypeThe type to evaluate.
Returns
- IList<SelectListItem>
A list for the given
type
.
GetSelectList(Type, Enum)
Gets a list of SelectListItem objects corresponding to enum constants defined in the given type. Also ensures the value
will round-trip even if it does not match a defined constant and sets the Selected property to true for one element in the returned list -- matching the value
.
public static IList<SelectListItem> GetSelectList(Type type, Enum value)
Parameters
Returns
- IList<SelectListItem>
A list for the given
type
, possibly extended to include an unrecognizedvalue
.
GetSelectList(ModelMetadata)
Gets a list of SelectListItem objects corresponding to enum constants defined in the given metadata.
public static IList<SelectListItem> GetSelectList(ModelMetadata metadata)
Parameters
metadata
ModelMetadataThe model metadata to evaluate.
Returns
- IList<SelectListItem>
A list for the given metadata.
GetSelectList(ModelMetadata, Enum)
Gets a list of SelectListItem objects corresponding to enum constants defined in the given metadata. Also ensures the value will round-trip even if it does not match a defined constant and sets the Selected property to true for one element in the returned list -- matching the value.
public static IList<SelectListItem> GetSelectList(ModelMetadata metadata, Enum value)
Parameters
metadata
ModelMetadataThe metadata to evaluate.
value
EnumValue from the type of metadata to select.
Returns
- IList<SelectListItem>
A list for the given
metadata
, possibly extended to include an unrecognizedvalue
.
IsValidForEnumHelper(Type)
Gets a value indicating whether the given type or an expression of this type is suitable for use in GetSelectList(Type) and EnumDropDownListFor<TModel, TEnum>(HtmlHelper<TModel>, Expression<Func<TModel, TEnum>>) calls.
public static bool IsValidForEnumHelper(Type type)
Parameters
type
TypeThe type to check.
Returns
- bool
true if GetSelectList(Type) will not throw when passed the given type and EnumDropDownListFor<TModel, TEnum>(HtmlHelper<TModel>, Expression<Func<TModel, TEnum>>) will not throw when passed an expression of this type; otherwise, false.
IsValidForEnumHelper(ModelMetadata)
Gets a value indicating whether the given metadata or associated expression is suitable for use in GetSelectList(ModelMetadata) and EnumDropDownListFor<TModel, TEnum>(HtmlHelper<TModel>, Expression<Func<TModel, TEnum>>) calls.
public static bool IsValidForEnumHelper(ModelMetadata metadata)
Parameters
metadata
ModelMetadataThe metadata to check.
Returns
- bool
true if GetSelectList(ModelMetadata) will return not throw when passed given ModelMetadata and EnumDropDownListFor<TModel, TEnum>(HtmlHelper<TModel>, Expression<Func<TModel, TEnum>>) will not throw when passed associated expression; otherwise, false.