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
FB2
LakshanF committed Jul 30, 2022
commit e31e0dc87a9fe4870336ea30ced1c9c300de381e
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(
/// </summary>
protected virtual IComparer Comparer => InvariantComparer.Default;

private static long GetEnumValue(bool isUnderlyingTypeUInt64, Enum enumVal, CultureInfo? culture)
private static long GetEnumValue(bool isUnderlyingTypeUInt64, object enumVal, CultureInfo? culture)
{
return isUnderlyingTypeUInt64 ?
unchecked((long)Convert.ToUInt64(enumVal, culture)) :
@@ -85,7 +85,7 @@ private static long GetEnumValue(bool isUnderlyingTypeUInt64, Enum enumVal, Cult
string[] values = strValue.Split(',');
foreach (string v in values)
{
convertedValue |= GetEnumValue(isUnderlyingTypeUInt64, (Enum)Enum.Parse(EnumType, v, true), culture);
convertedValue |= GetEnumValue(isUnderlyingTypeUInt64, Enum.Parse(EnumType, v, true), culture);
}
return Enum.ToObject(EnumType, convertedValue);
}
@@ -175,11 +175,10 @@ private static long GetEnumValue(bool isUnderlyingTypeUInt64, Enum enumVal, Cult
long[] ulValues = new long[objValues.Length];
for (int idx = 0; idx < objValues.Length; idx++)
{
ulValues[idx] = isUnderlyingTypeUInt64 ? unchecked((long)Convert.ToUInt64(objValues.GetValue(idx), culture)) :
Convert.ToInt64(objValues.GetValue(idx), culture);
ulValues[idx] = GetEnumValue(isUnderlyingTypeUInt64, objValues.GetValue(idx)!, culture);
}

long longValue = GetEnumValue(isUnderlyingTypeUInt64, (Enum)value, culture);
long longValue = GetEnumValue(isUnderlyingTypeUInt64, value, culture);
bool valueFound = true;
while (valueFound)
{
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Internal;

namespace System
{
2 changes: 1 addition & 1 deletion src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs
Original file line number Diff line number Diff line change
@@ -1436,7 +1436,7 @@ public static void Run()

Console.WriteLine("Enum.GetEnumValuesAsUnderlyingType");
jkotas marked this conversation as resolved.
Show resolved Hide resolved
{
if (Enum.GetEnumValuesAsUnderlyingType(typeof(Mine)).GetType() != typeof(int[]))
if (Enum.GetValuesAsUnderlyingType(typeof(Mine)).GetType() != typeof(int[]))
throw new Exception("GetEnumValuesAsUnderlyingType");
jkotas marked this conversation as resolved.
Show resolved Hide resolved
}