public static Delegate CreateDelegate(this MethodInfo MI) { if (MI == null) { throw new ArgumentException("MethodInfo MI cannot be null", "MI"); } return(Delegate.CreateDelegate(ReflectionRuntime.CreateDelegateType(MI.ReturnType, MI.GetParamTypes()), MI)); }
Delegate GetFunction(string Name, Type ReturnType, Type[] ArgTypes) { if (Functions.ContainsKey(Name)) { return(Functions[Name]); } if (ReturnType == typeof(object)) { ReturnType = typeof(void); } IntPtr ProcAddr = Kernel32.GetProcAddress(Module, Name); if (ProcAddr == IntPtr.Zero) { throw new Exception(string.Format("Function '{0}' not found in {1}", Name, LibraryName)); } Delegate D = Marshal.GetDelegateForFunctionPointer(ProcAddr, ReflectionRuntime.CreateDelegateType(ReturnType, ArgTypes, CConv)); Functions.Add(Name, D); return(D); }