Struct Enum<T>
Treats enum as a binary integer.
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
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
View Source
IsNegative
Gets a value indicating that the underlying value is negative.
Declaration
public bool IsNegative { get; }
Property Value
View Source
IsNotZero
Gets a value indicating that the underlying value is not zero.
Declaration
public bool IsNotZero { get; }
Property Value
View Source
IsOdd
Gets a value indicating that the underlying value is odd.
Declaration
public bool IsOdd { get; }
Property Value
View Source
IsPositive
Gets a value indicating that the underlying value is positive.
Declaration
public bool IsPositive { get; }
Property Value
View Source
IsPow2
Gets a value indicating that the underlying value is a power of two.
Declaration
public bool IsPow2 { get; }
Property Value
Methods
View Source
CompareTo(Enum<T>)
Declaration
public int CompareTo(Enum<T> other)
Parameters
| Type |
Name |
Description |
| Enum<T> |
other |
|
Returns
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
View Source
Equals(object?)
Declaration
public override bool Equals(object? other)
Parameters
| Type |
Name |
Description |
| object |
other |
|
Returns
Overrides
View Source
Equals(T)
Declaration
public bool Equals(T other)
Parameters
| Type |
Name |
Description |
| T |
other |
|
Returns
View Source
GetByteCount()
Declaration
public int GetByteCount()
Returns
View Source
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Overrides
View Source
GetShortestBitLength()
Declaration
public int GetShortestBitLength()
Returns
View Source
ToString()
Declaration
public override string ToString()
Returns
Overrides
View Source
Declaration
public bool TryFormat(Span<byte> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
Returns
View Source
Declaration
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
Returns
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
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
View Source
WriteBigEndian(Span<byte>)
Declaration
public int WriteBigEndian(Span<byte> destination)
Parameters
| Type |
Name |
Description |
| Span<byte> |
destination |
|
Returns
View Source
WriteLittleEndian(Span<byte>)
Declaration
public int WriteLittleEndian(Span<byte> destination)
Parameters
| Type |
Name |
Description |
| Span<byte> |
destination |
|
Returns
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 Parameters
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 Parameters
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 Parameters
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
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
View Source
Declaration
static Enum<T> Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)
Parameters
Returns
View Source
Declaration
static Enum<T> Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider)
Parameters
Returns
View Source
Declaration
static Enum<T> Parse(ReadOnlySpan<char> s, IFormatProvider? provider)
Parameters
Returns
View Source
ReadBigEndian(ReadOnlySpan<byte>, bool)
Declaration
static Enum<T> ReadBigEndian(ReadOnlySpan<byte> source, bool isUnsigned)
Parameters
Returns
View Source
ReadLittleEndian(ReadOnlySpan<byte>, bool)
Declaration
static Enum<T> ReadLittleEndian(ReadOnlySpan<byte> source, bool isUnsigned)
Parameters
Returns
View Source
TrailingZeroCount(Enum<T>)
Declaration
static Enum<T> TrailingZeroCount(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
View Source
Declaration
static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out Enum<T> result)
Parameters
Returns
View Source
Declaration
static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out Enum<T> result)
Parameters
Returns
View Source
Declaration
static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Enum<T> result)
Parameters
Returns
View Source
TryReadBigEndian(ReadOnlySpan<byte>, bool, out Enum<T>)
Declaration
static bool TryReadBigEndian(ReadOnlySpan<byte> source, bool isUnsigned, out Enum<T> value)
Parameters
Returns
View Source
TryReadLittleEndian(ReadOnlySpan<byte>, bool, out Enum<T>)
Declaration
static bool TryReadLittleEndian(ReadOnlySpan<byte> source, bool isUnsigned, out Enum<T> value)
Parameters
Returns
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
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
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
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
View Source
operator checked --(Enum<T>)
Declaration
static Enum<T> operator checked --(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
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
View Source
operator checked ++(Enum<T>)
Declaration
static Enum<T> operator checked ++(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
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
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
View Source
operator checked -(Enum<T>)
Declaration
static Enum<T> operator checked -(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
View Source
operator --(Enum<T>)
Declaration
static Enum<T> operator --(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
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
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
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
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
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
View Source
operator ++(Enum<T>)
Declaration
static Enum<T> operator ++(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
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
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
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
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
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
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
View Source
operator ~(Enum<T>)
Declaration
static Enum<T> operator ~(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
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
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
View Source
operator -(Enum<T>)
Declaration
static Enum<T> operator -(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
View Source
operator +(Enum<T>)
Declaration
static Enum<T> operator +(Enum<T> value)
Parameters
| Type |
Name |
Description |
| Enum<T> |
value |
|
Returns
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
Implements
Extension Methods