语言

ProtocolAttribute 类

定义

应用于表示 Objective-C 协议的接口的属性。

[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
继承
ProtocolAttribute
属性

注解

Xamarin.iOS 会将此属性作为协议的任何接口导出到 Objective-C,在导出到 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 ()
  {
  }
}

构造函数

名称 说明
ProtocolAttribute()

应用于表示 Objective-C 协议的接口的属性。

属性

名称 说明
BackwardsCompatibleCodeGeneration

此属性指示绑定生成器是否会为相关协议生成向后兼容的代码。

具体而言,如果此属性为 true,则绑定生成器将为所有协议成员的协议接口上的可选成员和 ProtocolMemberAttribute 属性生成扩展方法。

FormalSince

应用于表示 Objective-C 协议的接口的属性。

IsInformal

Objective-C 协议是否为非正式协议。

Name

协议的名称。

WrapperType

可用于包装此协议实例的特定托管类型。

适用于