You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I wanna do instantiate delegate instance from generic delegate type by read with ReadAssembly:
varassemblyResolver=newDefaultAssemblyResolver();assemblyResolver.AddSearchDirectory(basePath);vartestAssembly=AssemblyDefinition.ReadAssembly(Path.Combine(basePath,"TestTarget.dll"),newReaderParameters{AssemblyResolver=assemblyResolver});varmodule=testAssembly.MainModule;// Contains:// public delegate void TestGenericDelegate<TValue>(TValue value);vartestGenericDelegateTypeT=module.Types.First(t =>t.Name=="TestGenericDelegate`1")!;vartestGenericDelegateType=newGenericInstanceType(module.ImportReference(testGenericDelegateTypeT));testGenericDelegateType.GenericArguments.Add(module.TypeSystem.String);// HOW TO?:// Want to: TestGenericDelegate<string>// Will get unresolved generic argument constructor ref...vartestGenericDelegateTypeCtor=testGenericDelegateType.Resolve().Methods.First(m =>m.IsConstructor);// Will use: Instruction.Create(OpCodes.Newobj, testGenericDelegateTypeCtor)
The testGenericDelegateTypeCtor doesn't come from generic type instance,
it's generic method definition (IsDefinition == true).
How to do it?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I wanna do instantiate delegate instance from generic delegate type by read with ReadAssembly:
The
testGenericDelegateTypeCtor
doesn't come from generic type instance,it's generic method definition (
IsDefinition == true
).How to do it?
Verifying full sample code is here: https://github.com/kekyo/CecilTest/blob/main/CecilTest/Program.cs
Beta Was this translation helpful? Give feedback.
All reactions