Importer create ClassSig rather than GenericInstSig for generic type
See original GitHub issueI 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) { }
}
Issue Analytics
- State:
- Created a year ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Export a concrete version of a generic TypeScript class
Somehow the following works in TypeScript 4.6.3 : //specificthing.ts import { GenericThing } from "./genericthing"; export class ThingOwner ...
Read more >feat request: Ability to import generic type functions without ...
feat request: Ability to import generic type functions without duplicating the parameters. #32055.
Read more >Writing R Extensions
A package or ' R ' can appear more than once in the ' Depends ' field, for example to give upper and...
Read more >in (Generic Modifier) - C# Reference
For generic type parameters, the in keyword specifies that the type parameter is contravariant. You can use the in keyword in generic interfaces ......
Read more >(PDF) Datatype-generic programming | Jeremy Gibbons
A generic program is written once and works on values of many data types. Generic Haskell is a recent extension of the functional...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In old commit https://github.com/0xd4d/dnlib/commit/4ebebc1cd335676158688cc2e786de16b152f173#diff-3bc1d65c9144274297f0e9a1b2e194898aa3aa9e441d2956ab303ab4522dc554L488 code is
So I use “origField” instead of “fieldInfo”. But after running more tests I find “fieldInfo” is true.
Also I find more problems about generic like nested case of “MustTreatTypeAsGenericInstType”, wrong result of “FieldComparer.Equals”, inconsistent result of GetHashCode(SRM.FieldInfo) and GetHashCode(DNN.IField), ContainsGenericParameter for generic MemberRef always return true.
I will fix them these days.
PRs welcome. I don’t have time.