Table of Contents

Class EnumExtensions

Namespace
Plugin.BaseTypeExtensions
Assembly
Plugin.BaseTypeExtensions.dll

Provides extension methods for working with enum types, including flag manipulation and description retrieval.

public static class EnumExtensions
Inheritance
EnumExtensions
Inherited Members

Methods

AllAsArray<T>()

Returns all values of the specified enum type as an array.

public static IEnumerable<T> AllAsArray<T>()

Returns

IEnumerable<T>

An array of all enum values.

Type Parameters

T

The enum type.

AllAsFlag<T>()

Returns a value representing all flags set for the specified enum type.

public static T AllAsFlag<T>()

Returns

T

A value with all flags set.

Type Parameters

T

The enum type.

Count(Type)

Returns the number of values in the specified enum type.

public static int Count(this Type enumType)

Parameters

enumType Type

The enum type.

Returns

int

The number of values in the enum type.

Exceptions

ArgumentException

Thrown if enumType is not an enum type.

GetDescription(Enum)

Returns the description attribute of an enum value based on its DescriptionAttribute (if any) - otherwise the enum value name itself.

public static string GetDescription(this Enum value)

Parameters

value Enum

The enum value

Returns

string

The description attribute of the enum value

SetFlag<T>(T, T)

Sets the specified flag on the enum value.

public static T SetFlag<T>(this T @enum, T flag) where T : struct, Enum

Parameters

enum T

The enum value.

flag T

The flag to set.

Returns

T

The enum value with the flag set.

Type Parameters

T

The enum type.

TweakFlag<T>(T, T, bool)

Sets or unsets the specified flag on the enum value.

public static T TweakFlag<T>(this T @enum, T flag, bool on) where T : struct, Enum

Parameters

enum T

The enum value.

flag T

The flag to set or unset.

on bool

True to set the flag; false to unset it.

Returns

T

The enum value with the flag set or unset.

Type Parameters

T

The enum type.

UnsetFlag<T>(T, T)

Unsets the specified flag on the enum value.

public static T UnsetFlag<T>(this T @enum, T flag) where T : struct, Enum

Parameters

enum T

The enum value.

flag T

The flag to unset.

Returns

T

The enum value with the flag unset.

Type Parameters

T

The enum type.