Upravit

Sdílet prostřednictvím


ProtocolAttribute Class

Definition

Attribute applied to interfaces that represent Objective-C protocols.

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface)]
public sealed class ProtocolAttribute : Attribute
type ProtocolAttribute = class
    inherit Attribute
Inheritance
ProtocolAttribute
Attributes

Remarks

Xamarin.iOS will export any interfaces with this attribute as a protocol to Objective-C, and any classes that implement these interfaces will be marked as implementing the corresponding protocol when exported to Objective-C.

// This will create an Objective-C protocol called 'IMyProtocol', with one required member ('requiredMethod')
[Protocol ("IMyProtocol")]
interface IMyProtocol
{
  [Export ("requiredMethod")]
  void RequiredMethod ();
}

// This will export the equivalent of "@interface MyClass : NSObject <IMyProtocol>" to Objective-C.
class MyClass : NSObject, IMyProtocol
{
  void RequiredMethod ()
  {
  }
}

Constructors

ProtocolAttribute()

Properties

FormalSince
IsInformal

Whether the Objective-C protocol is an informal protocol.

Name

The name of the protocol.

WrapperType

The type of a specific managed type that can be used to wrap an instane of this protocol.

Applies to