Exemple #1
0
        public Delegate CreateDelegate(Type delegateType)
        {
            var dynamicType = typeBuilder.CreateType();

            assemblyBuilder.Save(fileName);
            Console.WriteLine("Saving file " + fileName);
            AssemblyAssert.IsValidAssembly(outputPath);
            MethodInfo methodInfo = dynamicType.GetMethod("DynamicMethod", BindingFlags.Static | BindingFlags.Public);

            return(Delegate.CreateDelegate(delegateType, methodInfo));
        }
        public Func <object[], object> CreateDelegate()
        {
            methodBuilder.GetILGenerator().Emit(OpCodes.Ret);
            var dynamicType = typeBuilder.CreateType();

            assemblyBuilder.Save(fileName);
            Console.WriteLine("Saving file " + fileName);
            AssemblyAssert.IsValidAssembly(outputPath);
            MethodInfo methodInfo = dynamicType.GetMethod("DynamicMethod", BindingFlags.Static | BindingFlags.Public);

            return((Func <object[], object>)Delegate.CreateDelegate(typeof(Func <object[], object>), methodInfo));
        }