Upravit

Sdílet prostřednictvím


MonoNativeFunctionWrapperAttribute Class

Definition

Attribute to apply to delegates to flag them as targets that can be used with GetDelegateForFunctionPointer(IntPtr, Type).

[System.AttributeUsage(System.AttributeTargets.Delegate)]
public sealed class MonoNativeFunctionWrapperAttribute : Attribute
type MonoNativeFunctionWrapperAttribute = class
    inherit Attribute
Inheritance
MonoNativeFunctionWrapperAttribute
Attributes

Remarks

Since Xamarin.iOS runs in fully statically compiled mode, it is necessary to flag delegate methods that might be passed to the GetDelegateForFunctionPointer(IntPtr, Type) with this attribute. This instructs the AOT compiler to generate the necessary code to allow a pointer to a native function to produce a callable managed delegate for the method.

[MonoNativeFunctionWrapper]
delegate void SomeDelegate (int a, int b);

// 
// the ptrToFunc points to an unmanaged C function with the signature (int a, int b)
void Callback (IntPtr ptrToFunc)
{
	var del = (SomeDelegate) Marshal.GetDelegateForFunctionPointer (ptrToFunc, typeof (SomeDelegate));

	// invoke it
	del (1, 2);
}

Constructors

MonoNativeFunctionWrapperAttribute()

Default constructor.

Applies to