Class Enumerator
Provides extension methods and utilities for enum types.
public static class Enumerator
  - Inheritance
 - 
      
      Enumerator
 
- Inherited Members
 
Methods
Contains(Enum, Enum)
Determines whether the enum value contains the specified flag. (Obsolete: Use Enum.HasFlag method.)
[Obsolete("Use Enum.HasFlag method.")]
public static bool Contains(this Enum enumSource, Enum enumPart)
  Parameters
Returns
- bool
 trueif the flag is present; otherwise,false.
Contains<T>(T, T)
Determines whether the specified enum value contains the given flag(s). (Obsolete: Use HasFlags method.)
[Obsolete("Use HasFlags method.")]
public static bool Contains<T>(T enumSource, T enumPart)
  Parameters
enumSourceTThe source enum value.
enumPartTThe flag(s) to check for.
Returns
- bool
 trueif the source contains the flag(s); otherwise,false.
Type Parameters
TThe enum type.
ExcludeNonBrowsable<T>(IEnumerable<T>)
Excludes non-browsable enum values from the collection.
public static IEnumerable<T> ExcludeNonBrowsable<T>(this IEnumerable<T> values)
  Parameters
valuesIEnumerable<T>The collection of enum values.
Returns
- IEnumerable<T>
 An enumerable of browsable enum values.
Type Parameters
TThe enum type.
ExcludeObsolete<T>(IEnumerable<T>)
Excludes obsolete enum values from the provided collection.
public static IEnumerable<T> ExcludeObsolete<T>(this IEnumerable<T> values)
  Parameters
valuesIEnumerable<T>The collection of enum values.
Returns
- IEnumerable<T>
 An enumerable without obsolete enum values.
Type Parameters
TThe enum type.
GetAttributeOfType<TAttribute>(object)
Retrieves an attribute of type TAttribute from the enum field value.
public static TAttribute GetAttributeOfType<TAttribute>(this object enumVal) where TAttribute : Attribute
  Parameters
enumValobjectThe enum value.
Returns
- TAttribute
 The attribute instance if found; otherwise,
null.
Type Parameters
TAttributeThe type of attribute to retrieve.
Exceptions
- ArgumentNullException
 Thrown when enumVal is null.
GetEnumBaseType(Type)
Gets the underlying type of the specified enum type.
public static Type GetEnumBaseType(this Type enumType)
  Parameters
enumTypeTypeThe enum type.
Returns
- Type
 The underlying numeric type for the enum.
GetEnumBaseType<T>()
Gets the underlying base type of the enum type T.
public static Type GetEnumBaseType<T>()
  Returns
- Type
 The underlying numeric type for the enum.
Type Parameters
TThe enum type.
GetName(Enum)
Gets the name of the enum value.
public static string GetName(this Enum value)
  Parameters
valueEnumThe enum value.
Returns
- string
 The name of the enum value.
GetName<T>(T)
Gets the name of the specified enum value.
public static string GetName<T>(T value)
  Parameters
valueTThe enum value.
Returns
- string
 The name of the enum value.
Type Parameters
TThe enum type.
GetNames(Type)
Gets all names of the specified enum type.
public static IEnumerable<string> GetNames(this Type enumType)
  Parameters
enumTypeTypeThe enum type.
Returns
- IEnumerable<string>
 An enumerable of enum names.
GetNames<T>()
Gets all names of the enum type T as a collection of strings.
public static IEnumerable<string> GetNames<T>()
  Returns
- IEnumerable<string>
 An enumerable of enum names.
Type Parameters
TThe enum type.
GetValues(Type)
Gets all enum values for the specified enum type as objects.
public static IEnumerable<object> GetValues(this Type enumType)
  Parameters
enumTypeTypeThe enum type.
Returns
- IEnumerable<object>
 An enumerable of enum values as objects.
GetValues<T>()
Gets all enum values of type T.
public static IEnumerable<T> GetValues<T>()
  Returns
- IEnumerable<T>
 An enumerable of all enum values.
Type Parameters
TThe enum type.
HasFlags<T>(T, T)
Determines whether the specified enum value has the given flag(s).
public static bool HasFlags<T>(T enumSource, T enumPart)
  Parameters
enumSourceTThe source enum value.
enumPartTThe flag(s) to check for.
Returns
- bool
 trueif the flag(s) are present; otherwise,false.
Type Parameters
TThe enum type.
IsDefined<T>(T)
Determines whether the specified enum value is defined in its type.
public static bool IsDefined<T>(this T enumValue)
  Parameters
enumValueTThe enum value.
Returns
- bool
 trueif the value is defined; otherwise,false.
Type Parameters
TThe enum type.
IsEnumBrowsable(object)
Determines whether the enum value is marked as browsable.
public static bool IsEnumBrowsable(this object enumVal)
  Parameters
enumValobjectThe enum value.
Returns
- bool
 trueif the enum value is browsable; otherwise,false.
IsFlags(Type)
Determines whether the specified enum type has the Flags attribute.
public static bool IsFlags(this Type enumType)
  Parameters
enumTypeTypeThe enum type.
Returns
- bool
 trueif the Flags attribute is present; otherwise,false.
JoinMask<T>()
Joins all flags of type T into a single masked enum value.
public static T JoinMask<T>()
  Returns
- T
 The joined masked enum value.
Type Parameters
TThe enum type.
JoinMask<T>(IEnumerable<T>)
Joins the provided collection of enum values into a single masked enum value.
public static T JoinMask<T>(this IEnumerable<T> values)
  Parameters
valuesIEnumerable<T>An enumerable of enum values.
Returns
- T
 The resulting joined masked enum value.
Type Parameters
TThe enum type.
Exceptions
- ArgumentNullException
 Thrown when values is null.
Remove<T>(Enum, T)
Removes the specified flag from the enum value.
public static T Remove<T>(this Enum enumSource, T enumPart)
  Parameters
enumSourceEnumThe source enum value.
enumPartTThe flag to remove.
Returns
- T
 The enum value after removal of the flag.
Type Parameters
TThe enum type.
Exceptions
- ArgumentException
 Thrown when the type of enumPart does not match enumSource.
Remove<T>(T, T)
Removes the specified flag(s) from the source enum value and returns the result.
public static T Remove<T>(T enumSource, T enumPart)
  Parameters
enumSourceTThe source enum value.
enumPartTThe flag(s) to remove.
Returns
- T
 The enum value after removal of the specified flag(s).
Type Parameters
TThe enum type.
SplitMask2(object)
Splits the masked enum value into its constituent flag values and returns them as objects.
public static IEnumerable<object> SplitMask2(this object maskedValue)
  Parameters
maskedValueobjectThe masked enum value.
Returns
- IEnumerable<object>
 An enumerable of individual flag values as objects.
Exceptions
- ArgumentNullException
 Thrown when maskedValue is null.
SplitMask<T>(T)
Splits the masked enum value into its constituent flag values of type T.
public static IEnumerable<T> SplitMask<T>(this T maskedValue)
  Parameters
maskedValueTThe masked enum value.
Returns
- IEnumerable<T>
 An enumerable of individual flag values of type T.
Type Parameters
TThe enum type.
TryParse<T>(string, out T, bool)
Attempts to parse the string to an enum value of type T.
public static bool TryParse<T>(this string str, out T value, bool ignoreCase = true) where T : struct
  Parameters
strstringThe string representation of the enum value.
valueTWhen this method returns, contains the enum value equivalent to the string, if the parse succeeded.
ignoreCaseboolif set to
trueignores case during parsing.
Returns
- bool
 trueif the parse was successful; otherwise,false.
Type Parameters
TThe enum type.