Skip to content

The original order is not utilised. #71

@Akeit0

Description

@Akeit0

For Enum.GetValues and GetNames , the elements of each array are sorted by the binary values.

Therefore, continuity checks should be performed after casting to unsigned, and minimum and maximum value searches can be easily performed on this basis. (If there is no value cover, the configuration of s_orderedMembers is also not necessary.)

static bool isContinuous(int uniqueCount, T max, T min)
{
if (uniqueCount <= 0)
return false;
var length = toUInt64(max) - toUInt64(min);
var count = (ulong)uniqueCount - 1;
return length == count;
}
static ulong toUInt64(T value)
{
return s_typeCode switch
{
TypeCode.SByte => (ulong)Unsafe.BitCast<T, sbyte>(value),
TypeCode.Byte => Unsafe.BitCast<T, byte>(value),
TypeCode.Int16 => (ulong)Unsafe.BitCast<T, short>(value),
TypeCode.UInt16 => Unsafe.BitCast<T, ushort>(value),
TypeCode.Int32 => (ulong)Unsafe.BitCast<T, int>(value),
TypeCode.UInt32 => Unsafe.BitCast<T, uint>(value),
TypeCode.Int64 => (ulong)Unsafe.BitCast<T, long>(value),
TypeCode.UInt64 => Unsafe.BitCast<T, ulong>(value),
_ => throw new InvalidOperationException(),
};

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions