MethodBuilder.SetMarshal(UnmanagedMarshal) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
An alternate API is available: Emit the MarshalAs custom attribute instead. http://go.microsoft.com/fwlink/?linkid=14202
设置此方法的返回类型的封送处理信息。
public:
void SetMarshal(System::Reflection::Emit::UnmanagedMarshal ^ unmanagedMarshal);
public void SetMarshal (System.Reflection.Emit.UnmanagedMarshal unmanagedMarshal);
[System.Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public void SetMarshal (System.Reflection.Emit.UnmanagedMarshal unmanagedMarshal);
member this.SetMarshal : System.Reflection.Emit.UnmanagedMarshal -> unit
[<System.Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
member this.SetMarshal : System.Reflection.Emit.UnmanagedMarshal -> unit
Public Sub SetMarshal (unmanagedMarshal As UnmanagedMarshal)
参数
- unmanagedMarshal
- UnmanagedMarshal
此方法的返回类型的封送处理信息。
- 属性
例外
该包含类型是以前使用 CreateType() 创建的。
- 或 -
对于当前的方法,属性 IsGenericMethod 为 true
,但属性 IsGenericMethodDefinition 为 false
。
示例
下面的代码示例演示了 方法的 SetMarshal
上下文用法,以将方法调用的结果作为另一种类型进行封送。
array<Type^>^ temp0 = { String::typeid };
MethodBuilder^ myMethod = myDynamicType->DefineMethod( "MyMethodReturnsMarshal",
MethodAttributes::Public,
UInt32::typeid,
temp0 );
// We want the return value of our dynamic method to be marshalled as
// an 64-bit (8-Byte) signed integer, instead of the default 32-bit
// unsigned int as specified above. The UnmanagedMarshal class can perform
// the type conversion.
UnmanagedMarshal^ marshalMeAsI8 = UnmanagedMarshal::DefineUnmanagedMarshal(
System::Runtime::InteropServices::UnmanagedType::I8 );
myMethod->SetMarshal( marshalMeAsI8 );
MethodBuilder myMethod = myDynamicType.DefineMethod("MyMethodReturnsMarshal",
MethodAttributes.Public,
typeof(uint),
new Type[] { typeof(string) });
// We want the return value of our dynamic method to be marshalled as
// an 64-bit (8-byte) signed integer, instead of the default 32-bit
// unsigned int as specified above. The UnmanagedMarshal class can perform
// the type conversion.
UnmanagedMarshal marshalMeAsI8 = UnmanagedMarshal.DefineUnmanagedMarshal(
System.Runtime.InteropServices.UnmanagedType.I8);
myMethod.SetMarshal(marshalMeAsI8);
Dim myMethod As MethodBuilder = myDynamicType.DefineMethod("MyMethodReturnsMarshal", _
MethodAttributes.Public, GetType(System.UInt32), _
New Type() {GetType(String)})
' We want the return value of our dynamic method to be marshalled as
' an 64-bit (8-byte) signed integer, instead of the default 32-bit
' unsigned int as specified above. The UnmanagedMarshal class can perform
' the type conversion.
Dim marshalMeAsI8 As UnmanagedMarshal = UnmanagedMarshal.DefineUnmanagedMarshal( _
System.Runtime.InteropServices.UnmanagedType.I8)
myMethod.SetMarshal(marshalMeAsI8)