public static Type GetOrCreate(MethodInfo mi) { var mpia = mi.GetAttribute <PInvokeAttribute>() ?? mi.DeclaringType.GetAttribute <PInvokeAttribute>(); var dyndelegate = new DynamicDelegate( mi.GetParameters().Select(p => DynamicDelegateParameter.FromParameterInfo(p, mpia)).ToArray(), DynamicDelegateParameter.FromParameterInfo(mi.ReturnParameter, mpia), mpia?.CallingConvention ?? 0); return(dyndelegate.GetOrCreate()); }
public DynamicDelegate(DynamicDelegateParameter[] parameters, DynamicDelegateParameter returnParameter, CallingConvention callingConvention) { ReturnParameter = returnParameter ?? DynamicDelegateParameter.Void; Parameters = parameters; CallingConvention = callingConvention; var id = new StringBuilder("D_"); ReturnParameter.AppendId(id); foreach (var par in Parameters) { id.Append('_'); par.AppendId(id); } Id = id.ToString(); }