Поделиться через


MonoNativeFunctionWrapperAttribute Класс

Определение

Атрибут, применяемый к делегатам, чтобы помечать их как целевые объекты, которые можно использовать с GetDelegateForFunctionPointer(IntPtr, Type).

[System.AttributeUsage(System.AttributeTargets.Delegate)]
public sealed class MonoNativeFunctionWrapperAttribute : Attribute
type MonoNativeFunctionWrapperAttribute = class
    inherit Attribute
Наследование
MonoNativeFunctionWrapperAttribute
Атрибуты

Комментарии

Так как Xamarin.iOS выполняется в полностью статически скомпилированном режиме, необходимо пометить методы делегатов, которые могут быть переданы в , с помощью этого атрибута GetDelegateForFunctionPointer(IntPtr, Type) . Это указывает компилятору AOT создать необходимый код, позволяющий указателю на собственную функцию создать вызываемый управляемый делегат для метода.

[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);
}

Конструкторы

MonoNativeFunctionWrapperAttribute()

Конструктор по умолчанию.

Применяется к