I'm using the system. reflection.Emit to implement google protocol message
I want to init a static field
class MessageA
{
static MessageParser<MessageA> Parser = new MessageParser<MessageA>(()=>new MessageA())
}
now MessageA is not created then i tried to get the constructor of Func it throws System.NotSupportedException with Message “Specified method is not supported.” here my example
using System.Reflection;
using System.Reflection.Emit;
Console.WriteLine("Hello, World!");
var assembleBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Dynamic"), AssemblyBuilderAccess.RunAndCollect);
var moduleBuilder = assembleBuilder.DefineDynamicModule("Dynamic.dll");
var typeA = moduleBuilder.DefineType("classA");
typeA.DefineDefaultConstructor(MethodAttributes.Public);
typeof(Func<>).MakeGenericType(typeA).GetConstructors();
How does the compiler do it?
