-
Notifications
You must be signed in to change notification settings - Fork 606
Closed
Description
I don't know if it's a .NET runtime bug or dnlib bug.
.NET runtime indicate different IsGenericTypeDefinition for the same type Task<>
dnlib create ClassSig since IsGenericType and IsGenericTypeDefinition are both True;
if (a.IsGenericType && !a.IsGenericTypeDefinition)
return ElementType.GenericInst;
using System;
using System.Reflection;
using System.Threading.Tasks;
using dnlib.DotNet;
class Program {
static void Main() {
var methodInfo1 = typeof(Task<string>).GetMethod("ContinueWith", new Type[] { typeof(Action<Task<string>>) });
Show(methodInfo1); // True
var methodInfo2 = typeof(Demo2<string>).GetMethod("Test");
Show(methodInfo2); // False
var moule = ModuleDefMD.Load(typeof(Program).Module);
var method1 = moule.Import(methodInfo1); // System.Threading.Tasks.Task System.Threading.Tasks.Task`1<System.String>::ContinueWith(System.Action`1<System.Threading.Tasks.Task`1>)
Show(method1); // Class
var method2 = moule.Import(methodInfo2); // System.Void Demo2`1<System.String>::Test(System.Action`1<System.Threading.Tasks.Task`1<System.String>>)
Show(method2); // GenericInst
Console.ReadKey();
}
static void Show(MethodInfo method) {
var origMethod = method.Module.ResolveMethod(method.MetadataToken);
var type = origMethod.GetParameters()[0].ParameterType.GenericTypeArguments[0];
Console.WriteLine(type.IsGenericTypeDefinition);
}
static void Show(IMethod method) {
var typeSig = (method.MethodSig.Params[0] as GenericInstSig).GenericArguments[0];
Console.WriteLine(typeSig.ElementType);
}
}
class Demo2<T> {
public void Test(Action<Task<T>> arg) { }
}
Metadata
Metadata
Assignees
Labels
No labels