ProvidePropertyAttribute 类

指定 IExtenderProvider 的实施者提供给其他组件的属性的名称。无法继承此类

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=True)> _
Public NotInheritable Class ProvidePropertyAttribute
    Inherits Attribute
用法
Dim instance As ProvidePropertyAttribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true)] 
public sealed class ProvidePropertyAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple=true)] 
public ref class ProvidePropertyAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true) */ 
public final class ProvidePropertyAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=true) 
public final class ProvidePropertyAttribute extends Attribute

备注

在用此特性标记类时,即通知代码生成器使用所提供的名称创建扩展程序属性。所标记的类必须实现 IExtenderProvider。因此,新的属性可以由容器中的其他组件使用。

在所标记的类内,必须实现 Get<name> 和 Set<name> 方法。例如,如果用 [ProvideProperty("PropertyName")] 标记了某个类,则必须实现 GetPropertyNameSetPropertyName 方法。若要指定新属性将是扩展程序属性,则必须从 IExtenderProvider 实现,还必须实现 CanExtend 方法。

有关更多信息,请参见 属性 (Attribute) 概述利用属性扩展元数据

示例

下面的示例使用 ProvidePropertyAttribute 标记 MyClass,该特性通知编译器从 GetMyPropertySetMyProperty 方法创建名为 MyProperty 的属性。

<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 'SetMyProperty

    ' 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
[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",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.
};
public class MyClass implements IExtenderProvider
{
    protected CultureInfo ciMine = null;

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

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

    /*  When you inherit from IExtenderProvider, you must implement the 
     *   CanExtend method. 
     */
    public boolean CanExtend(Object target)
    {
        return target instanceof Control;
    } //CanExtend
    
    // Insert additional code here.

} //MyClass 

继承层次结构

System.Object
   System.Attribute
    System.ComponentModel.ProvidePropertyAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ProvidePropertyAttribute 成员
System.ComponentModel 命名空间