Show / Hide Table of Contents

Struct Enum<T>

Treats enum as a binary integer.

Implements
IEquatable<T>
IBinaryInteger<Enum<T>>
IBinaryNumber<Enum<T>>
IBitwiseOperators<Enum<T>, Enum<T>, Enum<T>>
INumber<Enum<T>>
IComparable
IComparable<Enum<T>>
IComparisonOperators<Enum<T>, Enum<T>, bool>
IModulusOperators<Enum<T>, Enum<T>, Enum<T>>
INumberBase<Enum<T>>
IAdditionOperators<Enum<T>, Enum<T>, Enum<T>>
IAdditiveIdentity<Enum<T>, Enum<T>>
IDecrementOperators<Enum<T>>
IDivisionOperators<Enum<T>, Enum<T>, Enum<T>>
IEquatable<Enum<T>>
IEqualityOperators<Enum<T>, Enum<T>, bool>
IIncrementOperators<Enum<T>>
IMultiplicativeIdentity<Enum<T>, Enum<T>>
IMultiplyOperators<Enum<T>, Enum<T>, Enum<T>>
ISpanFormattable
IFormattable
ISpanParsable<Enum<T>>
IParsable<Enum<T>>
IUtf8SpanFormattable
IUtf8SpanParsable<Enum<T>>
ISubtractionOperators<Enum<T>, Enum<T>, Enum<T>>
IUnaryNegationOperators<Enum<T>, Enum<T>>
IUnaryPlusOperators<Enum<T>, Enum<T>>
IShiftOperators<Enum<T>, int, Enum<T>>
Inherited Members
object.GetType()
object.Equals(object, object)
object.ReferenceEquals(object, object)
Namespace: DotNext.Numerics
Assembly: DotNext.dll
Syntax
public readonly struct Enum<T> : IEquatable<T>, IBinaryInteger<Enum<T>>, IBinaryNumber<Enum<T>>, IBitwiseOperators<Enum<T>, Enum<T>, Enum<T>>, INumber<Enum<T>>, IComparable, IComparable<Enum<T>>, IComparisonOperators<Enum<T>, Enum<T>, bool>, IModulusOperators<Enum<T>, Enum<T>, Enum<T>>, INumberBase<Enum<T>>, IAdditionOperators<Enum<T>, Enum<T>, Enum<T>>, IAdditiveIdentity<Enum<T>, Enum<T>>, IDecrementOperators<Enum<T>>, IDivisionOperators<Enum<T>, Enum<T>, Enum<T>>, IEquatable<Enum<T>>, IEqualityOperators<Enum<T>, Enum<T>, bool>, IIncrementOperators<Enum<T>>, IMultiplicativeIdentity<Enum<T>, Enum<T>>, IMultiplyOperators<Enum<T>, Enum<T>, Enum<T>>, ISpanFormattable, IFormattable, ISpanParsable<Enum<T>>, IParsable<Enum<T>>, IUtf8SpanFormattable, IUtf8SpanParsable<Enum<T>>, ISubtractionOperators<Enum<T>, Enum<T>, Enum<T>>, IUnaryNegationOperators<Enum<T>, Enum<T>>, IUnaryPlusOperators<Enum<T>, Enum<T>>, IShiftOperators<Enum<T>, int, Enum<T>> where T : struct, Enum
Type Parameters
Name Description
T

The type of the enum.

Constructors

View Source

Enum(T)

Treats enum as a binary integer.

Declaration
public Enum(T value)
Parameters
Type Name Description
T value

The value to wrap.

Properties

View Source

IsEven

Gets a value indicating that the underlying value is even.

Declaration
public bool IsEven { get; }
Property Value
Type Description
bool
View Source

IsNegative

Gets a value indicating that the underlying value is negative.

Declaration
public bool IsNegative { get; }
Property Value
Type Description
bool
View Source

IsNotZero

Gets a value indicating that the underlying value is not zero.

Declaration
public bool IsNotZero { get; }
Property Value
Type Description
bool
View Source

IsOdd

Gets a value indicating that the underlying value is odd.

Declaration
public bool IsOdd { get; }
Property Value
Type Description
bool
View Source

IsPositive

Gets a value indicating that the underlying value is positive.

Declaration
public bool IsPositive { get; }
Property Value
Type Description
bool
View Source

IsPow2

Gets a value indicating that the underlying value is a power of two.

Declaration
public bool IsPow2 { get; }
Property Value
Type Description
bool

Methods

View Source

CompareTo(Enum<T>)

Declaration
public int CompareTo(Enum<T> other)
Parameters
Type Name Description
Enum<T> other
Returns
Type Description
int
View Source

ConvertChecked<TResult>()

Converts the underlying value to the specified type, or throws if the conversion is not available.

Declaration
public TResult ConvertChecked<TResult>() where TResult : INumberBase<TResult>
Returns
Type Description
TResult

The conversion result.

Type Parameters
Name Description
TResult

The type of the result.

Exceptions
Type Condition
OverflowException

The underlying value cannot be converted to TResult without overflow.

View Source

ConvertSaturating<TResult>()

Converts the underlying value to the specified type, or returns the maximum/minimum possible value for TResult if it overflows.

Declaration
public TResult ConvertSaturating<TResult>() where TResult : INumberBase<TResult>
Returns
Type Description
TResult

The conversion result.

Type Parameters
Name Description
TResult

The type of the result.

View Source

ConvertTruncating<TResult>()

Converts the underlying value to the specified type, or returns the truncated value that fits to TResult type.

Declaration
public TResult ConvertTruncating<TResult>() where TResult : INumberBase<TResult>
Returns
Type Description
TResult

The conversion result.

Type Parameters
Name Description
TResult

The type of the result.

View Source

Equals(Enum<T>)

Declaration
public bool Equals(Enum<T> other)
Parameters
Type Name Description
Enum<T> other
Returns
Type Description
bool
View Source

Equals(object?)

Declaration
public override bool Equals(object? other)
Parameters
Type Name Description
object other
Returns
Type Description
bool
Overrides
ValueType.Equals(object)
View Source

Equals(T)

Declaration
public bool Equals(T other)
Parameters
Type Name Description
T other
Returns
Type Description
bool
View Source

GetByteCount()

Declaration
public int GetByteCount()
Returns
Type Description
int
View Source

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
int
Overrides
ValueType.GetHashCode()
View Source

GetShortestBitLength()

Declaration
public int GetShortestBitLength()
Returns
Type Description
int
View Source

ToString()

Declaration
public override string ToString()
Returns
Type Description
string
Overrides
ValueType.ToString()
View Source

TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)

Declaration
public bool TryFormat(Span<byte> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
Type Name Description
Span<byte> destination
int charsWritten
ReadOnlySpan<char> format
IFormatProvider provider
Returns
Type Description
bool
View Source

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Declaration
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
Type Name Description
Span<char> destination
int charsWritten
ReadOnlySpan<char> format
IFormatProvider provider
Returns
Type Description
bool
View Source

TryWriteBigEndian(Span<byte>, out int)

Declaration
public bool TryWriteBigEndian(Span<byte> destination, out int bytesWritten)
Parameters
Type Name Description
Span<byte> destination
int bytesWritten
Returns
Type Description
bool
View Source

TryWriteLittleEndian(Span<byte>, out int)

Declaration
public bool TryWriteLittleEndian(Span<byte> destination, out int bytesWritten)
Parameters
Type Name Description
Span<byte> destination
int bytesWritten
Returns
Type Description
bool
View Source

WriteBigEndian(Span<byte>)

Declaration
public int WriteBigEndian(Span<byte> destination)
Parameters
Type Name Description
Span<byte> destination
Returns
Type Description
int
View Source

WriteLittleEndian(Span<byte>)

Declaration
public int WriteLittleEndian(Span<byte> destination)
Parameters
Type Name Description
Span<byte> destination
Returns
Type Description
int

Operators

View Source

explicit operator Enum<T>(T)

Converts the enum value to the underlying binary integer.

Declaration
public static explicit operator Enum<T>(T value)
Parameters
Type Name Description
T value

The value to wrap.

Returns
Type Description
Enum<T>

The binary integer that represents the enum value.

View Source

implicit operator T(Enum<T>)

Converts the enum container to its underlying value.

Declaration
public static implicit operator T(Enum<T> value)
Parameters
Type Name Description
Enum<T> value

The value to convert.

Returns
Type Description
T

The converted value.

Explicit Interface Implementations

View Source

CreateChecked<TOther>(TOther)

Declaration
static Enum<T> CreateChecked<TOther>(TOther value) where TOther : INumberBase<TOther>
Parameters
Type Name Description
TOther value
Returns
Type Description
Enum<T>
Type Parameters
Name Description
TOther
View Source

CreateSaturating<TOther>(TOther)

Declaration
static Enum<T> CreateSaturating<TOther>(TOther value) where TOther : INumberBase<TOther>
Parameters
Type Name Description
TOther value
Returns
Type Description
Enum<T>
Type Parameters
Name Description
TOther
View Source

CreateTruncating<TOther>(TOther)

Declaration
static Enum<T> CreateTruncating<TOther>(TOther value) where TOther : INumberBase<TOther>
Parameters
Type Name Description
TOther value
Returns
Type Description
Enum<T>
Type Parameters
Name Description
TOther
View Source

Max(Enum<T>, Enum<T>)

Declaration
static Enum<T> Max(Enum<T> x, Enum<T> y)
Parameters
Type Name Description
Enum<T> x
Enum<T> y
Returns
Type Description
Enum<T>
View Source

Min(Enum<T>, Enum<T>)

Declaration
static Enum<T> Min(Enum<T> x, Enum<T> y)
Parameters
Type Name Description
Enum<T> x
Enum<T> y
Returns
Type Description
Enum<T>
View Source

Parse(ReadOnlySpan<byte>, IFormatProvider?)

Declaration
static Enum<T> Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)
Parameters
Type Name Description
ReadOnlySpan<byte> utf8Text
IFormatProvider provider
Returns
Type Description
Enum<T>
View Source

Parse(ReadOnlySpan<char>, NumberStyles, IFormatProvider?)

Declaration
static Enum<T> Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider)
Parameters
Type Name Description
ReadOnlySpan<char> s
NumberStyles style
IFormatProvider provider
Returns
Type Description
Enum<T>
View Source

Parse(ReadOnlySpan<char>, IFormatProvider?)

Declaration
static Enum<T> Parse(ReadOnlySpan<char> s, IFormatProvider? provider)
Parameters
Type Name Description
ReadOnlySpan<char> s
IFormatProvider provider
Returns
Type Description
Enum<T>
View Source

ReadBigEndian(ReadOnlySpan<byte>, bool)

Declaration
static Enum<T> ReadBigEndian(ReadOnlySpan<byte> source, bool isUnsigned)
Parameters
Type Name Description
ReadOnlySpan<byte> source
bool isUnsigned
Returns
Type Description
Enum<T>
View Source

ReadLittleEndian(ReadOnlySpan<byte>, bool)

Declaration
static Enum<T> ReadLittleEndian(ReadOnlySpan<byte> source, bool isUnsigned)
Parameters
Type Name Description
ReadOnlySpan<byte> source
bool isUnsigned
Returns
Type Description
Enum<T>
View Source

TrailingZeroCount(Enum<T>)

Declaration
static Enum<T> TrailingZeroCount(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

TryParse(ReadOnlySpan<byte>, IFormatProvider?, out Enum<T>)

Declaration
static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out Enum<T> result)
Parameters
Type Name Description
ReadOnlySpan<byte> utf8Text
IFormatProvider provider
Enum<T> result
Returns
Type Description
bool
View Source

TryParse(ReadOnlySpan<char>, NumberStyles, IFormatProvider?, out Enum<T>)

Declaration
static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out Enum<T> result)
Parameters
Type Name Description
ReadOnlySpan<char> s
NumberStyles style
IFormatProvider provider
Enum<T> result
Returns
Type Description
bool
View Source

TryParse(ReadOnlySpan<char>, IFormatProvider?, out Enum<T>)

Declaration
static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Enum<T> result)
Parameters
Type Name Description
ReadOnlySpan<char> s
IFormatProvider provider
Enum<T> result
Returns
Type Description
bool
View Source

TryReadBigEndian(ReadOnlySpan<byte>, bool, out Enum<T>)

Declaration
static bool TryReadBigEndian(ReadOnlySpan<byte> source, bool isUnsigned, out Enum<T> value)
Parameters
Type Name Description
ReadOnlySpan<byte> source
bool isUnsigned
Enum<T> value
Returns
Type Description
bool
View Source

TryReadLittleEndian(ReadOnlySpan<byte>, bool, out Enum<T>)

Declaration
static bool TryReadLittleEndian(ReadOnlySpan<byte> source, bool isUnsigned, out Enum<T> value)
Parameters
Type Name Description
ReadOnlySpan<byte> source
bool isUnsigned
Enum<T> value
Returns
Type Description
bool
View Source

operator +(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator +(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator &(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator &(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator |(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator |(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator checked +(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator checked +(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator checked --(Enum<T>)

Declaration
static Enum<T> operator checked --(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

operator checked /(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator checked /(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator checked ++(Enum<T>)

Declaration
static Enum<T> operator checked ++(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

operator checked *(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator checked *(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator checked -(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator checked -(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator checked -(Enum<T>)

Declaration
static Enum<T> operator checked -(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

operator --(Enum<T>)

Declaration
static Enum<T> operator --(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

operator /(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator /(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator ==(Enum<T>, Enum<T>)

Declaration
static bool operator ==(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
bool
View Source

operator ^(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator ^(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator >(Enum<T>, Enum<T>)

Declaration
static bool operator >(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
bool
View Source

operator >=(Enum<T>, Enum<T>)

Declaration
static bool operator >=(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
bool
View Source

operator ++(Enum<T>)

Declaration
static Enum<T> operator ++(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

operator !=(Enum<T>, Enum<T>)

Declaration
static bool operator !=(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
bool
View Source

operator <<(Enum<T>, int)

Declaration
static Enum<T> operator <<(Enum<T> value, int shiftAmount)
Parameters
Type Name Description
Enum<T> value
int shiftAmount
Returns
Type Description
Enum<T>
View Source

operator <(Enum<T>, Enum<T>)

Declaration
static bool operator <(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
bool
View Source

operator <=(Enum<T>, Enum<T>)

Declaration
static bool operator <=(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
bool
View Source

operator %(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator %(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator *(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator *(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator ~(Enum<T>)

Declaration
static Enum<T> operator ~(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

operator >>(Enum<T>, int)

Declaration
static Enum<T> operator >>(Enum<T> value, int shiftAmount)
Parameters
Type Name Description
Enum<T> value
int shiftAmount
Returns
Type Description
Enum<T>
View Source

operator -(Enum<T>, Enum<T>)

Declaration
static Enum<T> operator -(Enum<T> left, Enum<T> right)
Parameters
Type Name Description
Enum<T> left
Enum<T> right
Returns
Type Description
Enum<T>
View Source

operator -(Enum<T>)

Declaration
static Enum<T> operator -(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

operator +(Enum<T>)

Declaration
static Enum<T> operator +(Enum<T> value)
Parameters
Type Name Description
Enum<T> value
Returns
Type Description
Enum<T>
View Source

operator >>>(Enum<T>, int)

Declaration
static Enum<T> operator >>>(Enum<T> value, int shiftAmount)
Parameters
Type Name Description
Enum<T> value
int shiftAmount
Returns
Type Description
Enum<T>

Implements

IEquatable<T>
IBinaryInteger<TSelf>
IBinaryNumber<TSelf>
IBitwiseOperators<TSelf, TOther, TResult>
INumber<TSelf>
IComparable
IComparable<T>
IComparisonOperators<TSelf, TOther, TResult>
IModulusOperators<TSelf, TOther, TResult>
INumberBase<TSelf>
IAdditionOperators<TSelf, TOther, TResult>
IAdditiveIdentity<TSelf, TResult>
IDecrementOperators<TSelf>
IDivisionOperators<TSelf, TOther, TResult>
IEquatable<T>
IEqualityOperators<TSelf, TOther, TResult>
IIncrementOperators<TSelf>
IMultiplicativeIdentity<TSelf, TResult>
IMultiplyOperators<TSelf, TOther, TResult>
ISpanFormattable
IFormattable
ISpanParsable<TSelf>
IParsable<TSelf>
IUtf8SpanFormattable
IUtf8SpanParsable<TSelf>
ISubtractionOperators<TSelf, TOther, TResult>
IUnaryNegationOperators<TSelf, TResult>
IUnaryPlusOperators<TSelf, TResult>
IShiftOperators<TSelf, TOther, TResult>

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
Leb128.TryWriteLeb128<T>(T, Span<byte>, out int)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
Number.Normalize<TInput, TOutput>(TInput, TInput, TInput)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾