private static Type MakeNewCustomDelegate(Type[] types) { #if FEATURE_COMPILE Type returnType = types[types.Length - 1]; Type[] parameters = types.RemoveLast(); TypeBuilder builder = AssemblyGen.DefineDelegateType("Delegate" + types.Length); builder.DefineConstructor(CtorAttributes, CallingConventions.Standard, s_delegateCtorSignature).SetImplementationFlags(ImplAttributes); builder.DefineMethod("Invoke", InvokeAttributes, returnType, parameters).SetImplementationFlags(ImplAttributes); return(builder.CreateTypeInfo()); #else throw new PlatformNotSupportedException(); #endif }
private static Type MakeNewCustomDelegate(Type[] types) { if (RuntimeFeature.IsDynamicCodeSupported) { Type returnType = types[types.Length - 1]; Type[] parameters = types.RemoveLast(); Type[] delegateCtorSignature = { typeof(object), typeof(IntPtr) }; const MethodAttributes ctorAttributes = MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public; const MethodImplAttributes implAttributes = MethodImplAttributes.Runtime | MethodImplAttributes.Managed; const MethodAttributes invokeAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual; TypeBuilder builder = AssemblyGen.DefineDelegateType("Delegate" + types.Length); builder.DefineConstructor(ctorAttributes, CallingConventions.Standard, delegateCtorSignature).SetImplementationFlags(implAttributes); builder.DefineMethod("Invoke", invokeAttributes, returnType, parameters).SetImplementationFlags(implAttributes); return(builder.CreateTypeInfo()); } else { throw new PlatformNotSupportedException(); } }