ProvidePropertyAttribute 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定 IExtenderProvider 實作者提供給其他元件的屬性名稱。 此類別無法獲得繼承。
public ref class ProvidePropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)]
public sealed class ProvidePropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)>]
type ProvidePropertyAttribute = class
inherit Attribute
Public NotInheritable Class ProvidePropertyAttribute
Inherits Attribute
- 繼承
- 屬性
範例
以下範例以 標記 MyClass ,指示編譯器從 and SetMyProperty 方法中建立一個屬性MyPropertyGetMyProperty。ProvidePropertyAttribute
[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;
// Provides the Get portion of MyProperty.
public CultureInfo GetMyProperty(Control myControl) =>
// Insert code here.
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) => 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 方法。
如需詳細資訊,請參閱屬性。
建構函式
| 名稱 | Description |
|---|---|
| ProvidePropertyAttribute(String, String) |
初始化該類別的新實例 ProvidePropertyAttribute ,並使用屬性名稱及其接收者的型別。 |
| ProvidePropertyAttribute(String, Type) |
初始化該類別的新實例 ProvidePropertyAttribute ,使用屬性名稱及其 Type。 |
屬性
| 名稱 | Description |
|---|---|
| PropertyName |
取得該類別所提供的屬性名稱。 |
| ReceiverTypeName |
取得該屬性可擴展的資料型別名稱。 |
| TypeId |
會為此屬性取得唯一識別碼。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
回傳給定物件的值是否等於當前 ProvidePropertyAttribute值。 |
| GetHashCode() |
傳回這個實例的哈希碼。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsDefaultAttribute() |
在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。 (繼承來源 Attribute) |
| Match(Object) |
在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
擷取 物件的型別資訊,可用來取得介面的類型資訊。 (繼承來源 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供物件所公開屬性和方法的存取權。 (繼承來源 Attribute) |