Skip to content

Commit

Permalink
Removed more .net 7 usage for better compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Dec 19, 2021
1 parent bb9b6a9 commit 4fc0300
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Debugging/ILRuntimeDebugEngine/ILRuntimeDebugEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ILRuntimeDebugEngine</RootNamespace>
<AssemblyName>ILRuntimeDebugEngine</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ILRuntimeDebuggerLauncher</RootNamespace>
<AssemblyName>ILRuntimeDebuggerLauncher</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
<IncludeDebugSymbolsInVSIXContainer>true</IncludeDebugSymbolsInVSIXContainer>
Expand Down
2 changes: 1 addition & 1 deletion ILRuntime/CLR/Method/CLRMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public IMethod MakeGenericMethod(IType[] genericArguments)
}

argString = argString.Substring(0, argString.Length - 2);
throw new Exception($"MakeGenericMethod failed : {def.DeclaringType.FullName}.{def.Name}<{argString}>");
throw new Exception(string.Format("MakeGenericMethod failed : {0}.{1}<{}>", def.DeclaringType.FullName, def.Name, argString));
}
#endif
var res = new CLRMethod(t, declaringType, appdomain);
Expand Down
15 changes: 10 additions & 5 deletions ILRuntime/CLR/Method/ILMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,19 @@ void PrewarmBody(HashSet<ILMethod> alreadyPrewarmed)
case OpCodeEnum.Callvirt:
{
var m = appdomain.GetMethod(ins.TokenInteger);
if (m is ILMethod ilm)
if (m is ILMethod)
{
ILMethod ilm = (ILMethod)m;
//如果参数alreadyPrewarmed不为空,则不仅prewarm当前方法,还会递归prewarm所有子调用
//如果参数alreadyPrewarmed为空,则只prewarm当前方法
if (alreadyPrewarmed != null)
{
ilm.Prewarm(alreadyPrewarmed);
}
}
else if (m is CLRMethod clrm)
else if (m is CLRMethod)
{
CLRMethod clrm = (CLRMethod)m;
ILRuntime.CLR.Utils.Extensions.GetTypeFlags(clrm.DeclearingType.TypeForCLR);
}
}
Expand Down Expand Up @@ -456,17 +458,19 @@ void PrewarmBodyRegister(HashSet<ILMethod> alreadyPrewarmed)
case OpCodeREnum.Callvirt:
{
var m = appdomain.GetMethod(ins.Operand);
if (m is ILMethod ilm)
if (m is ILMethod)
{
ILMethod ilm = (ILMethod)m;
//如果参数alreadyPrewarmed不为空,则不仅prewarm当前方法,还会递归prewarm所有子调用
//如果参数alreadyPrewarmed为空,则只prewarm当前方法
if (alreadyPrewarmed != null)
{
ilm.Prewarm(alreadyPrewarmed);
}
}
else if (m is CLRMethod clrm)
else if (m is CLRMethod)
{
CLRMethod clrm = (CLRMethod)m;
ILRuntime.CLR.Utils.Extensions.GetTypeFlags(clrm.DeclearingType.TypeForCLR);
}
}
Expand Down Expand Up @@ -510,8 +514,9 @@ private void Prewarm(HashSet<ILMethod> alreadyPrewarmed)
{
t = appdomain.GetType(v.VariableType, DeclearingType, this);
}
if (t is CLRType ct)
if (t is CLRType)
{
CLRType ct = (CLRType)t;
var fields = ct.Fields;
ILRuntime.CLR.Utils.Extensions.GetTypeFlags(ct.TypeForCLR);
}
Expand Down
4 changes: 2 additions & 2 deletions ILRuntime/CLR/TypeSystem/CLRType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public object PerformMemberwiseClone(object target)

if (memberwiseClone != null)
{
var del = (Func<object, object>)memberwiseClone.CreateDelegate(typeof(Func<object, object>));
var del = (Func<object, object>)Delegate.CreateDelegate(typeof(Func<object, object>), memberwiseClone);
memberwiseCloneDelegate = (ref object t) => del(t);
}
else
Expand Down Expand Up @@ -967,7 +967,7 @@ public IType MakeGenericInstance(KeyValuePair<string, IType>[] genericArguments)
}

argString = argString.Substring(0, argString.Length - 2);
throw new Exception($"MakeGenericType failed : {clrType.FullName}<{argString}>");
throw new Exception(string.Format("MakeGenericType failed : {0}<{1}>", clrType.FullName, argString));
}
#endif
var res = new CLRType(newType, appdomain);
Expand Down
5 changes: 4 additions & 1 deletion ILRuntime/Other/UncheckedStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
[Serializable]
[DebuggerDisplay("Count = {Count}")]
[ComVisible(false)]
public class UncheckedStack<T> : IEnumerable<T>, IEnumerable, ICollection, IReadOnlyCollection<T>
public class UncheckedStack<T> : IEnumerable<T>, IEnumerable, ICollection
#if NET_4_6 || NET_STANDARD_2_0
, IReadOnlyCollection<T>
#endif
{
[Serializable]
public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
Expand Down
3 changes: 2 additions & 1 deletion ILRuntime/Reflection/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static object CreateInstance(this CustomAttribute attribute, IType at, Ru
{
foreach (var j in attribute.Fields)
{
var field = it.GetField(j.Name, out int index);
int index;
var field = it.GetField(j.Name, out index);
if (field != null)
((ILRuntime.Runtime.Intepreter.ILTypeInstance)ins)[index] = j.Argument.Value;
}
Expand Down
7 changes: 6 additions & 1 deletion ILRuntime/Reflection/ILRuntimeMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,14 @@ public override Type ReturnType
{
get
{
return method.ReturnType?.ReflectionType;
if (method.ReturnType != null)
return method.ReturnType.ReflectionType;
else
return null;
}
}

#if NET_4_6 || NET_STANDARD_2_0
public override Delegate CreateDelegate(Type delegateType)
{
throw new NotSupportedException("please use CreateDelegate(Type delegateType, object target)");
Expand Down Expand Up @@ -216,5 +220,6 @@ public override Delegate CreateDelegate(Type delegateType, object target)
}
return del.GetConvertor(delegateType);
}
#endif
}
}
8 changes: 7 additions & 1 deletion ILRuntime/Reflection/ILRuntimePropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ public override Type PropertyType
}
}

public ILRuntime.Mono.Cecil.TypeReference Definition => definition.GetMethod != null ? definition.GetMethod.ReturnType : definition.SetMethod.Parameters [ 0 ].ParameterType;
public ILRuntime.Mono.Cecil.TypeReference Definition
{
get
{
return definition.GetMethod != null ? definition.GetMethod.ReturnType : definition.SetMethod.Parameters[0].ParameterType;
}
}


public override Type DeclaringType
Expand Down
2 changes: 2 additions & 0 deletions ILRuntime/Reflection/ILRuntimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,12 @@ public override int GetHashCode()
{
return type.GetHashCode();
}
#if NET_4_6 || NET_STANDARD_2_0
public override bool Equals(Type o)
{
return o is ILRuntimeType ? ((ILRuntimeType)o).type == type : false;
}
#endif
public override bool Equals(object o)
{
return o is ILRuntimeType ? ((ILRuntimeType)o).type == type : false;
Expand Down
1 change: 0 additions & 1 deletion ILRuntime/Runtime/CLRBinding/CLRBindingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ILRuntime.Runtime.CLRBinding
{
Expand Down
5 changes: 3 additions & 2 deletions ILRuntime/Runtime/Enviorment/AppDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ public void InitializeBindings(bool isThread = false)
UnityEngine.Debug.Log("CLRBindingUtils.Initialize Done in thread..");
#endif
});
thread.Name = $"CLRBindings-Thread #{thread.ManagedThreadId}";
thread.Name = string.Format("CLRBindings-Thread #{0}",thread.ManagedThreadId);
thread.Start();
}
else
Expand Down Expand Up @@ -853,8 +853,9 @@ public IType GetType(string fullname)
for (int i = 0; i < genericArguments.Length; i++)
{
string key = null;
if (bt is ILType ilt)
if (bt is ILType)
{
ILType ilt = (ILType)bt;
key = ilt.TypeDefinition.GenericParameters[i].FullName;
}
else
Expand Down
8 changes: 4 additions & 4 deletions ILRuntime/Runtime/Enviorment/CrossBindingCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void GenerateCrossBindingMethodBody(StringBuilder sb, List<MethodInfo> vi
StringBuilder sBuilder = new StringBuilder();
var p = i.GetParameters()[0];
p.ParameterType.GetClassName(out clsName, out realClsName, out isByRef, true);
pName = $"this [{realClsName + " " + p.Name}]";
pName = string.Format("this [{0}]", realClsName + " " + p.Name);

isIndexFunc = true;
}
Expand Down Expand Up @@ -192,8 +192,8 @@ static void GenerateCrossBindingMethodBody(StringBuilder sb, List<MethodInfo> vi
if (isProperty)
{
string baseMethodName = isIndexFunc
? $"base[{i.GetParameters()[0].Name}]"
: $"base.{i.Name.Substring(4)}";
? string.Format("base[{0}]", i.GetParameters()[0].Name)
: string.Format("base.{0}", i.Name.Substring(4));
if (isGetter)
{
sb.AppendLine(string.Format(" return {0};", baseMethodName));
Expand Down Expand Up @@ -597,7 +597,7 @@ static void GenInitParams(StringBuilder sb, ParameterInfo[] param)
{
if (p.IsOut)
{
sb.AppendLine($" {p.Name} = default({p.ParameterType.GetElementType().FullName});");
sb.AppendLine(string.Format(" {0} = default({1});", p.Name, p.ParameterType.GetElementType().FullName));
}
}
}
Expand Down
27 changes: 22 additions & 5 deletions ILRuntime/Runtime/Enviorment/InvocationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,31 @@ internal void SetInvoked(StackObject* esp)

internal StackObject* ESP
{
get => esp;
get
{
return esp;
}
set
{
esp = value;
}
}

internal ILIntepreter Intepreter => intp;
internal ILIntepreter Intepreter
{
get
{
return intp;
}
}

internal IList<object> ManagedStack => mStack;
internal IList<object> ManagedStack
{
get
{
return mStack;
}
}

public void PushBool(bool val)
{
Expand Down Expand Up @@ -300,7 +315,8 @@ public void PushValueType<T>(ref T obj)
Type t = typeof(T);
bool needPush = false;
StackObject* res = default(StackObject*);
if (domain.ValueTypeBinders.TryGetValue(t, out var binder))
ValueTypeBinder binder;
if (domain.ValueTypeBinders.TryGetValue(t, out binder))
{
var binderT = binder as ValueTypeBinder<T>;
if (binderT != null)
Expand Down Expand Up @@ -492,7 +508,8 @@ public T ReadValueType<T>()
CheckReturnValue();
Type t = typeof(T);
T res = default(T);
if (domain.ValueTypeBinders.TryGetValue(t, out var binder))
ValueTypeBinder binder;
if (domain.ValueTypeBinders.TryGetValue(t, out binder))
{
var binderT = binder as ValueTypeBinder<T>;
if (binderT != null)
Expand Down
1 change: 0 additions & 1 deletion ILRuntime/Runtime/ILRuntimeJITAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ILRuntime.Runtime
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ILRuntime.CLR.Method;

namespace ILRuntime.Runtime.Intepreter.RegisterVM
Expand Down
1 change: 0 additions & 1 deletion ILRuntime/Runtime/Stack/StackObjectAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ILRuntime.Runtime.Stack
{
Expand Down

0 comments on commit 4fc0300

Please sign in to comment.