Enumerator
Provides extension methods and utilities for enum types.
Methods
public static IEnumerable<T> ExcludeNonBrowsable<T>(IEnumerable<T> values)
result = Enumerator.ExcludeNonBrowsable(values)
Excludes non-browsable enum values from the collection.
- values
- The collection of enum values.
Returns: An enumerable of browsable enum values.
public static IEnumerable<T> ExcludeObsolete<T>(IEnumerable<T> values)
result = Enumerator.ExcludeObsolete(values)
Excludes obsolete enum values from the provided collection.
- values
- The collection of enum values.
Returns: An enumerable without obsolete enum values.
public static TAttribute GetAttributeOfType<TAttribute>(object enumVal)
result = Enumerator.GetAttributeOfType(enumVal)
Retrieves an attribute of type TAttribute from the enum field value.
- enumVal
- The enum value.
Returns: The attribute instance if found; otherwise, null.
public static Type GetEnumBaseType(Type enumType)
result = Enumerator.GetEnumBaseType(enumType)
Gets the underlying type of the specified enum type.
- enumType
- The enum type.
Returns: The underlying numeric type for the enum.
public static Type GetEnumBaseType<T>()
result = Enumerator.GetEnumBaseType()
Gets the underlying base type of the enum type T.
Returns: The underlying numeric type for the enum.
public static string GetName(Enum value)
result = Enumerator.GetName(value)
Gets the name of the enum value.
- value
- The enum value.
Returns: The name of the enum value.
public static IEnumerable<string> GetNames(Type enumType)
result = Enumerator.GetNames(enumType)
Gets all names of the specified enum type.
- enumType
- The enum type.
Returns: An enumerable of enum names.
public static IEnumerable<string> GetNames<T>()
result = Enumerator.GetNames()
Gets all names of the enum type T as a collection of strings.
Returns: An enumerable of enum names.
public static string GetName<T>(T value)
result = Enumerator.GetName(value)
Gets the name of the specified enum value.
- value
- The enum value.
Returns: The name of the enum value.
public static IEnumerable<object> GetValues(Type enumType)
result = Enumerator.GetValues(enumType)
Gets all enum values for the specified enum type as objects.
- enumType
- The enum type.
Returns: An enumerable of enum values as objects.
public static IEnumerable<T> GetValues<T>()
result = Enumerator.GetValues()
Gets all enum values of type T.
Returns: An enumerable of all enum values.
public static bool HasFlags<T>(T enumSource, T enumPart)
result = Enumerator.HasFlags(enumSource, enumPart)
Determines whether the specified enum value has the given flag(s).
- enumSource
- The source enum value.
- enumPart
- The flag(s) to check for.
Returns: true if the flag(s) are present; otherwise, false.
public static bool IsDefined<T>(T enumValue)
result = Enumerator.IsDefined(enumValue)
Determines whether the specified enum value is defined in its type.
- enumValue
- The enum value.
Returns: true if the value is defined; otherwise, false.
public static bool IsEnumBrowsable(object enumVal)
result = Enumerator.IsEnumBrowsable(enumVal)
Determines whether the enum value is marked as browsable.
- enumVal
- The enum value.
Returns: true if the enum value is browsable; otherwise, false.
public static bool IsFlags(Type enumType)
result = Enumerator.IsFlags(enumType)
Determines whether the specified enum type has the Flags attribute.
- enumType
- The enum type.
Returns: true if the Flags attribute is present; otherwise, false.
public static T JoinMask<T>(IEnumerable<T> values)
result = Enumerator.JoinMask(values)
Joins the provided collection of enum values into a single masked enum value.
- values
- An enumerable of enum values.
Returns: The resulting joined masked enum value.
public static T JoinMask<T>()
result = Enumerator.JoinMask()
Joins all flags of type T into a single masked enum value.
Returns: The joined masked enum value.
public static T Remove<T>(T enumSource, T enumPart)
result = Enumerator.Remove(enumSource, enumPart)
Removes the specified flag(s) from the source enum value and returns the result.
- enumSource
- The source enum value.
- enumPart
- The flag(s) to remove.
Returns: The enum value after removal of the specified flag(s).
public static T Remove<T>(Enum enumSource, T enumPart)
result = Enumerator.Remove(enumSource, enumPart)
Removes the specified flag from the enum value.
- enumSource
- The source enum value.
- enumPart
- The flag to remove.
Returns: The enum value after removal of the flag.
public static IEnumerable<object> SplitMask2(object maskedValue)
result = Enumerator.SplitMask2(maskedValue)
Splits the masked enum value into its constituent flag values and returns them as objects.
- maskedValue
- The masked enum value.
Returns: An enumerable of individual flag values as objects.
public static IEnumerable<T> SplitMask<T>(T maskedValue)
result = Enumerator.SplitMask(maskedValue)
Splits the masked enum value into its constituent flag values of type T.
- maskedValue
- The masked enum value.
Returns: An enumerable of individual flag values of type T.
public static bool TryParse<T>(string str, T value, bool ignoreCase)
result = Enumerator.TryParse(str, value, ignoreCase)
Attempts to parse the string to an enum value of type T.
- str
- The string representation of the enum value.
- value
- When this method returns, contains the enum value equivalent to the string, if the parse succeeded.
- ignoreCase
- if set to true ignores case during parsing.
Returns: true if the parse was successful; otherwise, false.