ProvidePropertyAttribute 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定 IExtenderProvider 的实施者提供给其他组件的属性的名称。 此类不能被继承。
public ref class ProvidePropertyAttribute sealed : Attribute[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)]
public sealed class ProvidePropertyAttribute : Attributepublic sealed class ProvidePropertyAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)>]
type ProvidePropertyAttribute = class
    inherit Attributetype ProvidePropertyAttribute = class
    inherit AttributePublic NotInheritable Class ProvidePropertyAttribute
Inherits Attribute- 继承
- 属性
示例
以下示例使用 ProvidePropertyAttribute 标记MyClass,告知编译器从 GetMyProperty 和 SetMyProperty 方法创建名为 MyProperty 的属性。
[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
注解
使用此属性标记类时,告知代码生成器使用你提供的名称创建扩展程序属性。 标记的类必须实现 IExtenderProvider。 因此,新属性可由容器中的其他组件使用。
在标记的类中,必须实现 Get<name> 和 Set<name> 方法。 例如,如果使用 [ProvideProperty (“PropertyName”) ] 标记类,则必须实现 GetPropertyName 和 SetPropertyName 方法。 若要将新属性指定为扩展器属性,必须从 IExtenderProvider实现 ,还必须实现 CanExtend 方法。
有关更多信息,请参阅特性。
构造函数
| ProvidePropertyAttribute(String, String) | 用该属性的名称和它的接收器类型初始化 ProvidePropertyAttribute 类的新实例。 | 
| ProvidePropertyAttribute(String, Type) | 用该属性的名称和它的 ProvidePropertyAttribute 初始化 Type 类的新实例。 | 
属性
| PropertyName | 获取该类提供的属性的名称。 | 
| ReceiverTypeName | 获取此属性可以扩展的数据类型的名称。 | 
| TypeId | 获取此特性的唯一标识符。 | 
| TypeId | 在派生类中实现时,获取此 Attribute 的唯一标识符。(继承自 Attribute) | 
方法
| Equals(Object) | 返回给定对象的值是否等于当前的 ProvidePropertyAttribute。 | 
| GetHashCode() | 返回此实例的哈希代码。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsDefaultAttribute() | 在派生类中重写时,指示此实例的值是否是派生类的默认值。(继承自 Attribute) | 
| Match(Object) | 当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。(继承自 Attribute) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
显式接口实现
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | 将一组名称映射为对应的一组调度标识符。(继承自 Attribute) | 
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute) | 
| _Attribute.GetTypeInfoCount(UInt32) | 检索对象提供的类型信息接口的数量(0 或 1)。(继承自 Attribute) | 
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | 提供对某一对象公开的属性和方法的访问。(继承自 Attribute) |