Show / Hide Table of Contents

Struct Enum<TEnum>

Provides strongly typed way to reflect enum type.

Implements
IEquatable<TEnum>
IComparable<TEnum>
IFormattable
IEquatable<Enum<TEnum>>
ISerializable
IConvertible<TEnum>
ICustomAttributeProvider
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: DotNext
Assembly: DotNext.dll
Syntax
[Serializable]
public struct Enum<TEnum> : IEquatable<TEnum>, IComparable<TEnum>, IFormattable, IEquatable<Enum<TEnum>>, ISerializable, IConvertible<TEnum>, ICustomAttributeProvider where TEnum : struct, Enum
Type Parameters
Name Description
TEnum

Enum type to reflect.

Fields

| Improve this Doc View Source

MaxValue

Maximum enum value.

Declaration
public static readonly Enum<TEnum> MaxValue
Field Value
Type Description
Enum<TEnum>
| Improve this Doc View Source

MinValue

Minimum enum value.

Declaration
public static readonly Enum<TEnum> MinValue
Field Value
Type Description
Enum<TEnum>

Properties

| Improve this Doc View Source

Members

Gets declared enum members.

Declaration
public static IReadOnlyList<Enum<TEnum>> Members { get; }
Property Value
Type Description
IReadOnlyList<Enum<TEnum>>
| Improve this Doc View Source

Name

Represents name of the enum member.

Declaration
public string Name { get; }
Property Value
Type Description
String
| Improve this Doc View Source

UnderlyingType

Gets the underlying type of the specified enumeration.

Declaration
public static Type UnderlyingType { get; }
Property Value
Type Description
Type
| Improve this Doc View Source

UnderlyingTypeCode

Gets code of the underlying primitive type.

Declaration
public static TypeCode UnderlyingTypeCode { get; }
Property Value
Type Description
TypeCode
| Improve this Doc View Source

Value

Represents value of the enum member.

Declaration
public TEnum Value { get; }
Property Value
Type Description
TEnum

Methods

| Improve this Doc View Source

CompareTo(TEnum)

Compares this enum value with other.

Declaration
public int CompareTo(TEnum other)
Parameters
Type Name Description
TEnum other

Other value to compare.

Returns
Type Description
Int32

Comparison result.

| Improve this Doc View Source

Equals(TEnum)

Determines whether this value equals to the other enum value.

Declaration
public bool Equals(TEnum other)
Parameters
Type Name Description
TEnum other

Other value to compare.

Returns
Type Description
Boolean

Equality check result.

| Improve this Doc View Source

Equals(Enum<TEnum>)

Determines whether two enum members are equal.

Declaration
public bool Equals(Enum<TEnum> other)
Parameters
Type Name Description
Enum<TEnum> other

Other member to compare.

Returns
Type Description
Boolean

true if this enum member is the same as other; otherwise, false.

| Improve this Doc View Source

Equals(Object)

Determines whether this value equals to the other enum value.

Declaration
public override bool Equals(object other)
Parameters
Type Name Description
Object other

Other value to compare.

Returns
Type Description
Boolean

Equality check result.

Overrides
ValueType.Equals(Object)
| Improve this Doc View Source

GetCustomAttribute<T>()

Retrieves a custom attribute of a specified type that is applied to this enum member.

Declaration
public T GetCustomAttribute<T>()

    where T : Attribute
Returns
Type Description
T

A custom attribute that matches T, or null if no such attribute is found.

Type Parameters
Name Description
T

The type of attribute to search for.

| Improve this Doc View Source

GetCustomAttributes<T>()

Retrieves a collection of custom attributes of a specified type that are applied to this enum member.

Declaration
public IEnumerable<T> GetCustomAttributes<T>()

    where T : Attribute
Returns
Type Description
IEnumerable<T>

A collection of the custom attributes that are applied to element and that match T, or an empty collection if no such attributes exist.

Type Parameters
Name Description
T

The type of attribute to search for.

| Improve this Doc View Source

GetHashCode()

Gets hash code of the enum member.

Declaration
public override int GetHashCode()
Returns
Type Description
Int32

The hash code of the enum member.

Overrides
ValueType.GetHashCode()
| Improve this Doc View Source

GetMember(TEnum)

Gets enum member by its value.

Declaration
public static Enum<TEnum> GetMember(TEnum value)
Parameters
Type Name Description
TEnum value

The enum value.

Returns
Type Description
Enum<TEnum>

The enum member.

| Improve this Doc View Source

GetMember(String)

Gets enum member by its case-sensitive name.

Declaration
public static Enum<TEnum> GetMember(string name)
Parameters
Type Name Description
String name

The name of the enum value.

Returns
Type Description
Enum<TEnum>

The enum member.

Exceptions
Type Condition
KeyNotFoundException

Enum member with the requested name doesn't exist in enum.

| Improve this Doc View Source

IsDefined(TEnum)

Returns an indication whether a constant with a specified value exists in a enumeration of type TEnum.

Declaration
public static bool IsDefined(TEnum value)
Parameters
Type Name Description
TEnum value

The value of a constant in TEnum.

Returns
Type Description
Boolean

true if a constant in TEnum has a value equal to value; otherwise, false.

| Improve this Doc View Source

IsDefined(String)

Returns an indication whether a constant with a specified name exists in a enumeration of type TEnum.

Declaration
public static bool IsDefined(string name)
Parameters
Type Name Description
String name

The name of a constant in TEnum.

Returns
Type Description
Boolean

true if a constant in TEnum has a name equal to name; otherwise, false.

| Improve this Doc View Source

IsDefined(Type, Boolean)

Indicates whether the one or more attributes of the specified type or of its derived types is applied to this enum value.

Declaration
public bool IsDefined(Type attributeType, bool inherit = false)
Parameters
Type Name Description
Type attributeType

The type of custom attribute to search for. The search includes derived types.

Boolean inherit

true to search this member's inheritance chain to find the attributes; otherwise, false.

Returns
Type Description
Boolean

true if one or more instances of attributeType or any of its derived types is applied to this member; otherwise, false.

| Improve this Doc View Source

IsFlag(TEnum)

Determines whether one or more bit fields associated with the current instance are set in the given value.

Declaration
public bool IsFlag(TEnum flags)
Parameters
Type Name Description
TEnum flags

An enumeration value.

Returns
Type Description
Boolean

true, if Value bits are set in flags.

| Improve this Doc View Source

ToString()

Returns textual representation of the enum value.

Declaration
public override string ToString()
Returns
Type Description
String

The textual representation of the enum value.

Overrides
ValueType.ToString()
| Improve this Doc View Source

TryGetMember(TEnum, out Enum<TEnum>)

Attempts to retrieve enum member which constant value is equal to the given value.

Declaration
public static bool TryGetMember(TEnum value, out Enum<TEnum> member)
Parameters
Type Name Description
TEnum value

Enum value.

Enum<TEnum> member

Enum member which constant value is equal to value.

Returns
Type Description
Boolean

true, if there are member declared the given constant value exist; otherwise, false.

| Improve this Doc View Source

TryGetMember(String, out Enum<TEnum>)

Attempts to retrieve enum member which name is equal to the given value.

Declaration
public static bool TryGetMember(string name, out Enum<TEnum> member)
Parameters
Type Name Description
String name

The name of a constant.

Enum<TEnum> member

Enum member which name is equal to name.

Returns
Type Description
Boolean

true, if there are member declared the given constant value exist; otherwise, false.

Operators

| Improve this Doc View Source

Equality(Enum<TEnum>, Enum<TEnum>)

Determines whether two enum members are equal.

Declaration
public static bool operator ==(Enum<TEnum> first, Enum<TEnum> second)
Parameters
Type Name Description
Enum<TEnum> first

The first member to compare.

Enum<TEnum> second

The second member to compare.

Returns
Type Description
Boolean

true if this enum member is the same as other; otherwise, false.

| Improve this Doc View Source

Implicit(Enum<TEnum> to TEnum)

Converts typed enum wrapper into actual enum value.

Declaration
public static implicit operator TEnum(in Enum<TEnum> en)
Parameters
Type Name Description
Enum<TEnum> en

Enum wrapper to convert.

Returns
Type Description
TEnum
| Improve this Doc View Source

Inequality(Enum<TEnum>, Enum<TEnum>)

Determines whether two enum members are not equal.

Declaration
public static bool operator !=(Enum<TEnum> first, Enum<TEnum> second)
Parameters
Type Name Description
Enum<TEnum> first

The first member to compare.

Enum<TEnum> second

The second member to compare.

Returns
Type Description
Boolean

true if this enum member is not the same as other; otherwise, false.

Explicit Interface Implementations

| Improve this Doc View Source

IConvertible<TEnum>.Convert()

Declaration
TEnum IConvertible<TEnum>.Convert()
Returns
Type Description
TEnum
| Improve this Doc View Source

IFormattable.ToString(String, IFormatProvider)

Declaration
string IFormattable.ToString(string format, IFormatProvider provider)
Parameters
Type Name Description
String format
IFormatProvider provider
Returns
Type Description
String
| Improve this Doc View Source

ICustomAttributeProvider.GetCustomAttributes(Boolean)

Declaration
object[] ICustomAttributeProvider.GetCustomAttributes(bool inherit)
Parameters
Type Name Description
Boolean inherit
Returns
Type Description
Object[]
| Improve this Doc View Source

ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

Declaration
object[] ICustomAttributeProvider.GetCustomAttributes(Type attributeType, bool inherit)
Parameters
Type Name Description
Type attributeType
Boolean inherit
Returns
Type Description
Object[]
| Improve this Doc View Source

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Declaration
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info
StreamingContext context

Implements

System.IEquatable<T>
System.IComparable<T>
System.IFormattable
System.IEquatable<T>
System.Runtime.Serialization.ISerializable
IConvertible<T>
System.Reflection.ICustomAttributeProvider

Extension Methods

ValueTypeExtensions.IsOneOf<T>(T, IEnumerable<T>)
ValueTypeExtensions.IsOneOf<T>(T, T[])
CustomAttribute.IsDefined<TAttribute>(ICustomAttributeProvider, Boolean)
Sequence.Skip<TEnumerator, T>(ref TEnumerator, Int32)
ExpressionBuilder.Const<T>(T)

See Also

EnumMember API
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX