편집

다음을 통해 공유


AdoptsAttribute Class

Definition

An attribute used to specify that a class adopts a specific Objective-C protocol.

[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)]
public sealed class AdoptsAttribute : Attribute
type AdoptsAttribute = class
    inherit Attribute
Inheritance
AdoptsAttribute
Attributes

Remarks

You can use this attribute to decorate NSObject-derived classes to report back to the Objective-C runtime that the class adopts the specified Objective-C protocol.

Unlike C# interfaces, Objective-C protocols have optional components which means that they are not directly mapped to C# constructs. In both the Xamarin.iOS and Xamarin.Mac Framework bindings, protocols are usually inlined directly into the classes that adopt the protocols. This allows developers to invoke any methods adopted by the system classes.

User subclasses use this attribute when they want to explicitly inform the Objective-C runtime that they adopt the protocol. This attribute is looked up by the NSObject.ConformsToProtocol method.

An alternative method of specifying that a class adopts a specific Objective-C protocol is to make the class implement the managed interface for the protocol (usually the name of the protocol prefixed by I).

//
// The following examples are both equivalent
//

[Adopts ("UITableViewDelegate")]
class MyTableViewA : UITableView
{
}

class MyTableViewB : UITableView, IUITableViewDelegate
{
}

This has the advantage that the managed compiler will enforce the implementation of required protocol members, and the IDE will show intellisense to implement any protocol member.

Constructors

AdoptsAttribute(String)

Properties

ProtocolHandle

Returns the underlying handle to the Protocol.

ProtocolType

The name of the protocol type adopted.

Applies to