Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new API GetEnumValuesAsUnderlyingType #73057

Merged
merged 18 commits into from
Aug 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
workaround mono test failures
LakshanF committed Aug 2, 2022

Verified

This commit was signed with the committer’s verified signature.
nsarlin-zama Nicolas Sarlin
commit b71f4665827b60775716fb538e9815174ddfc42b
37 changes: 37 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs
Original file line number Diff line number Diff line change
@@ -158,9 +158,18 @@ public override Array GetEnumValuesAsUnderlyingType()
// Get all of the values
ulong[] values = Enum.InternalGetValues(this);

#if MONO
switch (GetTypeCode(Enum.GetUnderlyingType(this)))
LakshanF marked this conversation as resolved.
Show resolved Hide resolved
#else
switch (RuntimeTypeHandle.GetCorElementType(this))
#endif
{

#if MONO
case TypeCode.Byte:
#else
case CorElementType.ELEMENT_TYPE_U1:
#endif
{
var ret = new byte[values.Length];
for (int i = 0; i < values.Length; i++)
@@ -170,7 +179,11 @@ public override Array GetEnumValuesAsUnderlyingType()
return ret;
}

#if MONO
case TypeCode.UInt16:
#else
case CorElementType.ELEMENT_TYPE_U2:
#endif
{
var ret = new ushort[values.Length];
for (int i = 0; i < values.Length; i++)
@@ -180,7 +193,11 @@ public override Array GetEnumValuesAsUnderlyingType()
return ret;
}

#if MONO
case TypeCode.UInt32:
#else
case CorElementType.ELEMENT_TYPE_U4:
#endif
{
var ret = new uint[values.Length];
for (int i = 0; i < values.Length; i++)
@@ -190,12 +207,20 @@ public override Array GetEnumValuesAsUnderlyingType()
return ret;
}

#if MONO
case TypeCode.UInt64:
#else
case CorElementType.ELEMENT_TYPE_U8:
#endif
{
return (Array)values.Clone();
}

#if MONO
case TypeCode.SByte:
#else
case CorElementType.ELEMENT_TYPE_I1:
#endif
{
var ret = new sbyte[values.Length];
for (int i = 0; i < values.Length; i++)
@@ -205,7 +230,11 @@ public override Array GetEnumValuesAsUnderlyingType()
return ret;
}

#if MONO
case TypeCode.Int16:
#else
case CorElementType.ELEMENT_TYPE_I2:
#endif
{
var ret = new short[values.Length];
for (int i = 0; i < values.Length; i++)
@@ -215,7 +244,11 @@ public override Array GetEnumValuesAsUnderlyingType()
return ret;
}

#if MONO
case TypeCode.Int32:
#else
case CorElementType.ELEMENT_TYPE_I4:
#endif
{
var ret = new int[values.Length];
for (int i = 0; i < values.Length; i++)
@@ -225,7 +258,11 @@ public override Array GetEnumValuesAsUnderlyingType()
return ret;
}

#if MONO
case TypeCode.Int64:
#else
case CorElementType.ELEMENT_TYPE_I8:
#endif
{
var ret = new long[values.Length];
for (int i = 0; i < values.Length; i++)