ProvidePropertyAttribute Kelas

Definisi

Menentukan nama properti yang ditawarkan oleh pelaksana IExtenderProvider ke komponen lain. Kelas ini tidak dapat diwariskan.

public ref class ProvidePropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)]
public sealed class ProvidePropertyAttribute : Attribute
public sealed class ProvidePropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)>]
type ProvidePropertyAttribute = class
    inherit Attribute
type ProvidePropertyAttribute = class
    inherit Attribute
Public NotInheritable Class ProvidePropertyAttribute
Inherits Attribute
Warisan
ProvidePropertyAttribute
Atribut

Contoh

Contoh berikut menandai MyClass dengan ProvidePropertyAttribute yang memberi tahu pengkompilasi untuk membuat properti yang disebut MyProperty dari GetMyProperty metode dan SetMyProperty .

[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

Keterangan

Saat Anda menandai kelas dengan atribut ini, Anda memberi tahu generator kode untuk membuat properti extender dengan nama yang Anda berikan. Kelas yang ditandai harus menerapkan IExtenderProvider. Akibatnya, properti baru dapat digunakan oleh komponen lain dalam kontainer.

Dalam kelas yang ditandai, Anda harus menerapkan Get<metode nama> dan Set<nama> . Misalnya, jika Anda menandai kelas dengan [ProvideProperty("PropertyName")], Anda harus menerapkan GetPropertyName metode dan SetPropertyName . Untuk menentukan bahwa properti baru akan menjadi properti extender, Anda harus menerapkan dari IExtenderProvider, Anda juga harus menerapkan CanExtend metode .

Untuk informasi selengkapnya, lihat Atribut.

Konstruktor

ProvidePropertyAttribute(String, String)

Menginisialisasi instans ProvidePropertyAttribute baru kelas dengan nama properti dan jenis penerimanya.

ProvidePropertyAttribute(String, Type)

Menginisialisasi instans ProvidePropertyAttribute baru kelas dengan nama properti dan Type.

Properti

PropertyName

Mendapatkan nama properti yang disediakan kelas ini.

ReceiverTypeName

Mendapatkan nama tipe data yang dapat diperluas properti ini.

TypeId

Mendapatkan pengidentifikasi unik untuk atribut ini.

TypeId

Ketika diimplementasikan di kelas turunan, mendapatkan pengidentifikasi unik untuk ini Attribute.

(Diperoleh dari Attribute)

Metode

Equals(Object)

Mengembalikan apakah nilai objek yang diberikan sama dengan saat ini ProvidePropertyAttribute.

GetHashCode()

Mengembalikan kode hash untuk instans ini.

GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk