Table of Contents

Class EnumExtensions

Namespace
HeroKit.Enums
Assembly
HeroKit.dll

Provides extension methods for enums.

public static class EnumExtensions
Inheritance
EnumExtensions
Inherited Members

Methods

IsDefined<T>(T)

Checks whether a value is defined in its enum type.

public static bool IsDefined<T>(this T value) where T : struct, Enum

Parameters

value T

The value to check.

Returns

bool

True if the value is defined; otherwise false.

Type Parameters

T

The enum type.

ToByte(Enum)

Converts an enum value to a byte.

public static byte ToByte(this Enum value)

Parameters

value Enum

The enum value to convert.

Returns

byte

The underlying value as a byte.

Exceptions

OverflowException

The underlying value does not fit in a byte.

ToList<TEnum>()

Returns all values defined in an enum type.

public static List<TEnum> ToList<TEnum>() where TEnum : struct, Enum

Returns

List<TEnum>

A list of all defined values in declaration order.

Type Parameters

TEnum

The enum type.

Examples

EnumExtensions.ToList<DayOfWeek>(); // Sunday … Saturday

ToUnderlying<T>(Enum)

Converts an enum value to its underlying numeric value in the requested type.

public static T ToUnderlying<T>(this Enum value) where T : struct, IConvertible

Parameters

value Enum

The enum value.

Returns

T

The underlying value.

Type Parameters

T

The numeric type, for example int or long.

Examples

DayOfWeek.Friday.ToUnderlying<int>(); // 5