DefaultInterfaceAttribute 类


指定托管 Windows 运行时类的默认接口。Specifies the default interface of a managed Windows Runtime class.

public ref class DefaultInterfaceAttribute sealed : Attribute
public sealed class DefaultInterfaceAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=false, Inherited=false)]
public sealed class DefaultInterfaceAttribute : Attribute
type DefaultInterfaceAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=false, Inherited=false)>]
type DefaultInterfaceAttribute = class
    inherit Attribute
Public NotInheritable Class DefaultInterfaceAttribute
Inherits Attribute


当你开发 Windows 运行时Windows Runtime 组件时,如果你想要指定用于封送应用特性的类的默认接口,请使用此特性。When you develop Windows 运行时Windows Runtime Components, use this attribute when you want to specify the default interface that is used to marshal the class the attribute is applied to. 如果允许自动生成类接口,则不需要这样做。This is not necessary if you allow the class interfaces to be generated automatically.

Windows 运行时Windows Runtime类必须有一个默认接口。A Windows 运行时Windows Runtime class must have a default interface. 如果 WinMdExp.exe 实用程序在生成组件时未检测到该类的默认接口 Windows 运行时Windows Runtime ,它会选择一个接口,如下所示:If the WinMdExp.exe utility does not detect a default interface for a class when it builds your Windows 运行时Windows Runtimecomponent, it chooses an interface as follows:

  • 如果类已自动生成接口,则使用第一个接口作为默认值。If the class has automatically generated interfaces, it uses the first one as the default.

  • 如果类没有任何自动生成的接口,它将使用类的接口实现列表中的第一个接口。If the class doesn't have any automatically generated interfaces, it uses the first interface in the class's interface implementation list.

可以将属性应用于 DefaultInterfaceAttribute 类,或将属性应用于 Windows.Foundations.Metadata.DefaultAttribute 接口。You can apply the DefaultInterfaceAttribute attribute to the class, or apply the Windows.Foundations.Metadata.DefaultAttribute attribute to an interface. 如果同时提供两个属性,则后者优先。The latter takes precedence if both attributes are supplied.



初始化 DefaultInterfaceAttribute 类的新实例。Initializes a new instance of the DefaultInterfaceAttribute class.



获取默认接口的类型。Gets the type of the default interface.


在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)



返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)


_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)