From a3c9ac4e937499ede9461d3108fab617cf8692c9 Mon Sep 17 00:00:00 2001 From: liiir1985 Date: Fri, 25 Jan 2019 10:59:39 +0800 Subject: [PATCH] resolved #257 --- ILRuntime/CLR/Method/ILMethod.cs | 22 +++++++++---------- ILRuntime/CLR/TypeSystem/ILType.cs | 6 ++--- ILRuntime/CLR/Utils/Extensions.cs | 2 +- ILRuntime/Runtime/Enviorment/AppDomain.cs | 4 ++-- .../TestFramework/GenericExtensions.cs | 5 +++++ TestCases/GenericMethodTest.cs | 5 +++++ 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/ILRuntime/CLR/Method/ILMethod.cs b/ILRuntime/CLR/Method/ILMethod.cs index 8de3f97f..a3b3cdd6 100644 --- a/ILRuntime/CLR/Method/ILMethod.cs +++ b/ILRuntime/CLR/Method/ILMethod.cs @@ -529,7 +529,7 @@ bool CheckHasGenericParamter(object token) { TypeReference _ref = ((TypeReference)token); if (_ref.IsArray) - return CheckHasGenericParamter(_ref.GetElementType()); + return CheckHasGenericParamter(((ArrayType)_ref).ElementType); if (_ref.IsGenericParameter) return true; if (_ref.IsGenericInstance) @@ -577,16 +577,16 @@ void InitParameters() bool isArray = false; int rank = 1; TypeReference pt = i.ParameterType; - if (i.ParameterType.IsByReference) + if (pt.IsByReference) { isByRef = true; - pt = pt.GetElementType(); + pt = ((ByReferenceType)pt).ElementType; } - if (i.ParameterType.IsArray) + if (pt.IsArray) { isArray = true; rank = ((ArrayType)pt).Rank; - pt = pt.GetElementType(); + pt = ((ArrayType)pt).ElementType; } if (pt.IsGenericParameter) { @@ -609,14 +609,14 @@ void InitParameters() else throw new NotSupportedException("Cannot find Generic Parameter " + pt.Name + " in " + def.FullName); } - - if (isByRef) - type = type.MakeByRefType(); - if (isArray) - type = type.MakeArrayType(rank); } else - type = appdomain.GetType(i.ParameterType, declaringType, this); + type = appdomain.GetType(pt, declaringType, this); + + if (isByRef) + type = type.MakeByRefType(); + if (isArray) + type = type.MakeArrayType(rank); parameters.Add(type); } } diff --git a/ILRuntime/CLR/TypeSystem/ILType.cs b/ILRuntime/CLR/TypeSystem/ILType.cs index 6dfdf12a..a7880b5e 100644 --- a/ILRuntime/CLR/TypeSystem/ILType.cs +++ b/ILRuntime/CLR/TypeSystem/ILType.cs @@ -286,7 +286,7 @@ void RetriveDefinitino(TypeReference def) definition = null; } else - RetriveDefinitino(def.GetElementType()); + RetriveDefinitino(((TypeSpecification)def).ElementType); } else definition = def as TypeDefinition; @@ -517,7 +517,7 @@ void InitializeBaseType() if (definition.BaseType.IsGenericInstance) { GenericInstanceType git = definition.BaseType as GenericInstanceType; - var elementType = appdomain.GetType(definition.BaseType.GetElementType(), this, null); + var elementType = appdomain.GetType(git.ElementType, this, null); if (elementType is CLRType) { for (int i = 0; i < git.GenericArguments.Count; i++) @@ -536,7 +536,7 @@ void InitializeBaseType() if (specialProcess) { //如果泛型参数是自身,则必须要特殊处理,否则会StackOverflow - var elementType = appdomain.GetType(definition.BaseType.GetElementType(), this, null); + var elementType = appdomain.GetType(((GenericInstanceType)definition.BaseType).ElementType, this, null); foreach (var i in appdomain.CrossBindingAdaptors) { if (i.Key.IsGenericType && !i.Key.IsGenericTypeDefinition) diff --git a/ILRuntime/CLR/Utils/Extensions.cs b/ILRuntime/CLR/Utils/Extensions.cs index 36c10336..826055ae 100644 --- a/ILRuntime/CLR/Utils/Extensions.cs +++ b/ILRuntime/CLR/Utils/Extensions.cs @@ -30,7 +30,7 @@ public static List GetParamList(this MethodReference def, ILRuntime.Runti if ((t == null && def.IsGenericInstance) || (t != null && t.HasGenericParameter)) { GenericInstanceMethod gim = (GenericInstanceMethod)def; - string name = i.ParameterType.IsByReference ? i.ParameterType.GetElementType().FullName : i.ParameterType.FullName; + string name = i.ParameterType.IsByReference ? ((ByReferenceType)i.ParameterType).ElementType.FullName : i.ParameterType.FullName; for (int j = 0; j < gim.GenericArguments.Count; j++) { diff --git a/ILRuntime/Runtime/Enviorment/AppDomain.cs b/ILRuntime/Runtime/Enviorment/AppDomain.cs index 329be0fb..ad36e55c 100644 --- a/ILRuntime/Runtime/Enviorment/AppDomain.cs +++ b/ILRuntime/Runtime/Enviorment/AppDomain.cs @@ -726,7 +726,7 @@ internal IType GetType(object token, IType contextType, IMethod contextMethod) } if (_ref.IsByReference) { - var et = _ref.GetElementType(); + var et = ((ByReferenceType)_ref).ElementType; bool valid = !et.ContainsGenericParameter; var t = GetType(et, contextType, contextMethod); if (t != null) @@ -750,7 +750,7 @@ internal IType GetType(object token, IType contextType, IMethod contextMethod) if (_ref.IsArray) { ArrayType at = (ArrayType)_ref; - var t = GetType(_ref.GetElementType(), contextType, contextMethod); + var t = GetType(at.ElementType, contextType, contextMethod); if (t != null) { res = t.MakeArrayType(at.Rank); diff --git a/ILRuntimeTest/TestFramework/GenericExtensions.cs b/ILRuntimeTest/TestFramework/GenericExtensions.cs index b7b983ba..68644211 100644 --- a/ILRuntimeTest/TestFramework/GenericExtensions.cs +++ b/ILRuntimeTest/TestFramework/GenericExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using ILRuntime.Other; @@ -38,5 +39,9 @@ public static void StaticMethod(Func func) { } public static void StaticMethod(Func func) { } public static void StaticMethod(Func> func) { } public static void StaticMethod(Func> func) { } + public static void Method(string name, params KeyValuePair[] panels) + { + Console.WriteLine("进来了"); + } } } diff --git a/TestCases/GenericMethodTest.cs b/TestCases/GenericMethodTest.cs index 95189105..785a888a 100644 --- a/TestCases/GenericMethodTest.cs +++ b/TestCases/GenericMethodTest.cs @@ -502,5 +502,10 @@ public static void GenericStaticMethodTest11() a.TestMethod(out aa); b.TestMethod(out bb); } + + public static void GenericStaticMethodTest12() + { + ILRuntimeTest.TestBase.StaticGenericMethods.Method(""); + } } }