NSObject.ConformsToProtocol(IntPtr) 方法

定义

调用 以确定此对象是否实现指定的协议。

[Foundation.Export("conformsToProtocol:")]
[Foundation.Preserve]
public virtual bool ConformsToProtocol (IntPtr protocol);
abstract member ConformsToProtocol : nativeint -> bool
override this.ConformsToProtocol : nativeint -> bool

参数

protocol
IntPtr

nativeint

指向协议的指针。

返回

如果类实现协议,则必须返回 true。

实现

属性

注解

如果需要类响应 Objective-C 对 对象的查询,以确定是否实现指定的协议,则可以重写此方法。

可以将 IntPtr 值与使用指定协议创建 AdoptsAttribute 并提取其 ProtocolHandle 的结果进行比较。

static AdoptsAttribute myProtocol = new AdoptsAttribute ("MyProtocol");
public override ConformsToProtocol (IntPtr protocol)
{
	if (protocol == myProtocol.ProtocolHandle)
		return true;
	return false;
}

尽管通常只需使用 AdoptsAttribute 将类除散,并让运行时为你执行此操作,如下所示:

[Adopts ("UITextInput")]
[Register ("MyCoreView")]
public class EditableCoreTextView : UIView {
	[Export ("inputDelegate")]
	public UITextInputDelegate InputDelegate {...}
}

有关 AdoptsAttribute 的完整示例,请参阅 SimpleTextInput 示例

适用于