本文整理汇总了C#中System.Reflection.Emit.TypeBuilder.DefinePInvokeMethod方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.DefinePInvokeMethod方法的具体用法?C# TypeBuilder.DefinePInvokeMethod怎么用?C# TypeBuilder.DefinePInvokeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.DefinePInvokeMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildMemoryManagementType
static Type BuildMemoryManagementType(TypeBuilder typeBuilder, Type memMgmtType, string dllName)
{
foreach (MethodInfo method in memMgmtType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
{
ParameterInfo[] paramInfos = method.GetParameters();
Type[] parameterTypes = new Type[paramInfos.Length];
for (int i = 0; i < paramInfos.Length; i++)
{
parameterTypes[i] = paramInfos[i].ParameterType;
}
ParameterInfo returnParamInfo = method.ReturnParameter;
MethodBuilder methodBuilder =
typeBuilder.DefinePInvokeMethod(
method.Name, dllName,
MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.PinvokeImpl,
CallingConventions.Standard,
returnParamInfo.ParameterType, parameterTypes,
callingConvention, charset);
methodBuilder.SetImplementationFlags(MethodImplAttributes.PreserveSig);
}
return typeBuilder.CreateType();
}
示例2: GrabPInvokeImpl
protected MethodInfo GrabPInvokeImpl(MethodInfo Original, TypeBuilder On)
{
if (On == null)
On = GrabType(Original.DeclaringType) as TypeBuilder;
DllImportAttribute Attr = FindCustomAttribute<DllImportAttribute>(Original);
if (Attr == null)
throw new InvalidOperationException("P/Invoke method without a DllImportAttribute");
Type ReturnType = GrabType(Original.ReturnType);
Type[] Parameters = ParameterTypes(Original);
if (MethodsDone.ContainsKey(Original))
return MethodsDone[Original];
MethodBuilder PInvoke = On.DefinePInvokeMethod(Original.Name, Attr.Value, Original.Attributes, Original.CallingConvention,
ReturnType, Parameters, Attr.CallingConvention, Attr.CharSet);
PInvoke.SetImplementationFlags(Original.GetMethodImplementationFlags());
MethodsDone.Add(Original, PInvoke);
return PInvoke;
}