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
屬性

範例

下列範例會將 MyClass 標記為 ProvidePropertyAttribute,告知編譯器從 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 <name > 和 Set @no__t 3name > 方法。Within the marked class, you must implement Get <name> and Set <name> methods. 例如,如果您使用 [ProvideProperty ("PropertyName")] 來標記類別,則必須執行 GetPropertyName 和 @no__t 1 方法。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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。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)

適用於