Skip to content

Commit

Permalink
Fixed a problem with Enum.HasFlag not avaliable on .net 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed May 1, 2020
1 parent 7ebafcd commit 12d4b59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ILRuntime/ILRuntime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ILRuntime</RootNamespace>
<AssemblyName>ILRuntime</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions ILRuntime/Runtime/Enviorment/AppDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ public unsafe AppDomain()
{
RegisterCLRMethodRedirection(i, CLRRedirections.EnumGetName);
}
#if NET_4_6 || NET_STANDARD_2_0
if(i.Name == "HasFlag")
{
RegisterCLRMethodRedirection(i, CLRRedirections.EnumHasFlag);
}
#endif
if (i.Name == "ToObject" && i.GetParameters()[1].ParameterType == typeof(int))
{
RegisterCLRMethodRedirection(i, CLRRedirections.EnumToObject);
Expand Down
13 changes: 7 additions & 6 deletions ILRuntime/Runtime/Enviorment/CLRRedirections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ unsafe static class CLRRedirections
if (p != null)
{
object[] arr = (object[])p;
for(int i = 0; i < ilmethod.ParameterCount; i++)
for (int i = 0; i < ilmethod.ParameterCount; i++)
{
esp = ILIntepreter.PushObject(esp, mStack, CheckCrossBindingAdapter(arr[i]));
}
Expand Down Expand Up @@ -966,9 +966,9 @@ static object CheckCrossBindingAdapter(object obj)
else
{
int val;
if(int.TryParse(name, out val))
if (int.TryParse(name, out val))
{
if((int)f.Constant == val)
if ((int)f.Constant == val)
{
ILEnumTypeInstance ins = new ILEnumTypeInstance(it);
ins[0] = f.Constant;
Expand Down Expand Up @@ -1016,7 +1016,7 @@ static object CheckCrossBindingAdapter(object obj)
var f = fields[i];
if (f.IsStatic)
{
if(list == null)
if (list == null)
{
if (f.Constant is long)
{
Expand Down Expand Up @@ -1102,7 +1102,7 @@ static object CheckCrossBindingAdapter(object obj)
if (t is ILRuntimeType)
{
ILType it = ((ILRuntimeType)t).ILType;

List<string> res = new List<string>();
if (it.IsEnum)
{
Expand Down Expand Up @@ -1165,7 +1165,7 @@ static object CheckCrossBindingAdapter(object obj)
else
return ILIntepreter.PushObject(ret, mStack, Enum.GetName(t, val), true);
}

#if NET_4_6 || NET_STANDARD_2_0
public static StackObject* EnumHasFlag(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj)
{
var ret = esp - 1 - 1;
Expand Down Expand Up @@ -1195,5 +1195,6 @@ static object CheckCrossBindingAdapter(object obj)
else
return ILIntepreter.PushZero(ret);
}
#endif
}
}

0 comments on commit 12d4b59

Please sign in to comment.