Share via


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
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface)>]
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

BackwardsCompatibleCodeGeneration

This property indicates whether the binding generator will generate backwards-compatible code for the protocol in question.

In particular, if this property is true, then the binding generator will generate extension methods for optional members and ProtocolMemberAttribute attributes on the protocol interface for all protocol members.

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