ProvidePropertyAttribute 类

定义

指定 IExtenderProvider 的实施者提供给其他组件的属性的名称。Specifies the name of the property that an implementer of IExtenderProvider offers to other components. 无法继承此类。This class cannot be inherited.

public ref class ProvidePropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)]
public sealed class ProvidePropertyAttribute : Attribute
type ProvidePropertyAttribute = class
    inherit Attribute
Public NotInheritable Class ProvidePropertyAttribute
Inherits Attribute
继承
ProvidePropertyAttribute
属性

示例

下面的示例使用一个 ProvidePropertyAttribute 标记 MyClass,该告诉编译器从 GetMyPropertySetMyProperty 方法创建名为 MyProperty 的属性。The following example marks MyClass with a ProvidePropertyAttribute that tells the compiler to create a property called MyProperty from the GetMyProperty and SetMyProperty methods.

[ProvideProperty("MyProperty",Control::typeid)]
public ref class MyClass: public IExtenderProvider
{
protected:
   CultureInfo^ ciMine;

public:
   // Provides the Get portion of MyProperty. 
   CultureInfo^ GetMyProperty( Control^ myControl )
   {
      // Insert code here.
      return ciMine;
   }

   // Provides the Set portion of MyProperty.
   void SetMyProperty( Control^ myControl, String^ value )
   {
      // Insert code here.
   }

   /* When you inherit from IExtenderProvider, you must implement the 
        * CanExtend method. */
   virtual bool CanExtend( Object^ target )
   {
      return dynamic_cast<Control^>(target) != nullptr;
   }
   // Insert additional code here.
};
[ProvideProperty("MyProperty", typeof(Control))]
public class MyClass : IExtenderProvider {
    protected CultureInfo ciMine = null;
    // Provides the Get portion of MyProperty. 
    public CultureInfo GetMyProperty(Control myControl) {
        // Insert code here.
        return ciMine;
    }
    
    // Provides the Set portion of MyProperty.
    public void SetMyProperty(Control myControl, string value) {
        // Insert code here.
    }
    
    /* When you inherit from IExtenderProvider, you must implement the 
     * CanExtend method. */
    public bool CanExtend(Object target) {
        return(target is Control);
    }
    
    // Insert additional code here.
 }
<ProvideProperty("MyProperty", GetType(Control))> _
Public Class SampleClass
    Implements IExtenderProvider
    Protected ciMine As CultureInfo = Nothing

    ' Provides the Get portion of MyProperty. 
    Public Function GetMyProperty(myControl As Control) As CultureInfo
        ' Insert code here.
        Return ciMine
    End Function 'GetMyProperty

    ' Provides the Set portion of MyProperty.
    Public Sub SetMyProperty(myControl As Control, value As String)
        ' Insert code here.
    End Sub

    ' When you inherit from IExtenderProvider, you must implement the 
    ' CanExtend method. 
    Public Function CanExtend(target As [Object]) As Boolean Implements IExtenderProvider.CanExtend
        Return TypeOf target Is Control
    End Function 'CanExtend

    ' Insert additional code here.

End Class

注解

标记具有此特性的类时,通知代码生成器使用您提供的名称创建一个扩展程序属性。When you mark a class with this attribute, you tell the code generator to create an extender property with the name you provide. 标记的类必须实现 IExtenderProviderThe marked class must implement IExtenderProvider. 因此,新属性可由容器中的其他组件使用。As a result, the new property can be used by other components in a container.

在标记的类中,必须实现 Get <名称 > 并 Set <名称 > 方法。Within the marked class, you must implement Get <name> and Set <name> methods. 例如,如果使用 [ProvideProperty ("属性名称")] 标记一个类,则必须实现 GetPropertyNameSetPropertyName 方法。For example, if you mark a class with [ProvideProperty("PropertyName")], you must implement GetPropertyName and SetPropertyName methods. 若要将新属性指定为扩展程序属性,则必须实现 IExtenderProvider,还必须实现 CanExtend 方法。To specify that the new property will be an extender property, you must implement from IExtenderProvider, you must also implement a CanExtend method.

有关更多信息,请参阅特性For more information, see Attributes.

构造函数

ProvidePropertyAttribute(String, String)

用该属性的名称和它的接收器类型初始化 ProvidePropertyAttribute 类的新实例。Initializes a new instance of the ProvidePropertyAttribute class with the name of the property and the type of its receiver.

ProvidePropertyAttribute(String, Type)

用该属性的名称和它的 ProvidePropertyAttribute 初始化 Type 类的新实例。Initializes a new instance of the ProvidePropertyAttribute class with the name of the property and its Type.

属性

PropertyName

获取该类提供的属性的名称。Gets the name of a property that this class provides.

ReceiverTypeName

获取此属性可以扩展的数据类型的名称。Gets the name of the data type this property can extend.

TypeId

获取此特性的唯一标识符。Gets a unique identifier for this attribute.

方法

Equals(Object)

返回给定对象的值是否等于当前的 ProvidePropertyAttributeReturns whether the value of the given object is equal to the current ProvidePropertyAttribute.

GetHashCode()

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

GetType()

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

(继承自 Object)
IsDefaultAttribute()

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

(继承自 Attribute)
Match(Object)

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

(继承自 Attribute)
MemberwiseClone()

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

(继承自 Object)
ToString()

返回表示当前对象的字符串。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)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(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)

适用于