MergablePropertyAttribute Kelas

Definisi

Menentukan bahwa properti ini dapat digabungkan dengan properti milik objek lain dalam jendela Properti.

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

Contoh

Contoh berikut menandai properti yang sesuai untuk digabungkan.

public:
   [MergableProperty(true)]
   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }
      void set( int value )
      {
         // Insert code here.
      }
   }
[MergableProperty(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }
<MergableProperty(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

Contoh berikutnya menunjukkan cara memeriksa nilai MergablePropertyAttribute untuk MyProperty. Pertama kode mendapatkan PropertyDescriptorCollection dengan semua properti untuk objek . Selanjutnya diindeks ke PropertyDescriptorCollection dalam untuk mendapatkan MyProperty. Kemudian mengembalikan atribut untuk properti ini dan menyimpannya dalam variabel atribut.

Contohnya menyajikan dua cara berbeda untuk memeriksa nilai MergablePropertyAttribute. Dalam fragmen kode kedua, contoh memanggil Equals metode dengan static nilai . Dalam fragmen kode terakhir, contoh menggunakan AllowMerge properti untuk memeriksa nilai.

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes;

// Checks to see if the value of the MergablePropertyAttribute is Yes.
if ( attributes[ MergablePropertyAttribute::typeid ]->Equals( MergablePropertyAttribute::Yes ) )
{
   // Insert code here.
}

// This is another way to see if the property is bindable.
MergablePropertyAttribute^ myAttribute = dynamic_cast<MergablePropertyAttribute^>(attributes[ MergablePropertyAttribute::typeid ]);
if ( myAttribute->AllowMerge )
{
   // Insert code here.
}
// Gets the attributes for the property.
 AttributeCollection attributes = 
    TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
 
 // Checks to see if the value of the MergablePropertyAttribute is Yes.
 if(attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes)) {
    // Insert code here.
 }
 
 // This is another way to see if the property is bindable.
 MergablePropertyAttribute myAttribute = 
    (MergablePropertyAttribute)attributes[typeof(MergablePropertyAttribute)];
 if(myAttribute.AllowMerge) {
    // Insert code here.
 }
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("MyProperty").Attributes

' Checks to see if the value of the MergablePropertyAttribute is Yes.
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
    ' Insert code here.
End If 

' This is another way to see if the property is bindable.
Dim myAttribute As MergablePropertyAttribute = _
    CType(attributes(GetType(MergablePropertyAttribute)), MergablePropertyAttribute)
If myAttribute.AllowMerge Then
    ' Insert code here.
End If

Jika Anda menandai kelas dengan MergablePropertyAttribute, gunakan kode berikut untuk memeriksa nilainya.

AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ MergablePropertyAttribute::typeid ]->Equals( MergablePropertyAttribute::Yes ) )
{
   // Insert code here.
}
AttributeCollection attributes = 
    TypeDescriptor.GetAttributes(MyProperty);
 if(attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes)) {
    // Insert code here.
 }
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
    ' Insert code here.
End If

Keterangan

Properti yang ditandai dengan MergablePropertyAttribute set ke true dapat digabungkan dengan properti milik objek lain di jendela Properti. Properti yang ditandai dengan set ke MergablePropertyAttributefalse harus ditampilkan secara terpisah. Default adalah true.

Catatan

Saat Anda menandai properti dengan diatur MergablePropertyAttribute ke true, nilai atribut ini diatur ke anggota Yeskonstanta . Untuk properti yang ditandai dengan properti yang MergablePropertyAttribute diatur ke false, nilainya adalah No. Oleh karena itu, ketika Anda ingin memeriksa nilai atribut ini dalam kode Anda, Anda harus menentukan atribut sebagai MergablePropertyAttribute.Yes atau MergablePropertyAttribute.No.

Untuk informasi selengkapnya, lihat Atribut.

Konstruktor

MergablePropertyAttribute(Boolean)

Menginisialisasi instans baru kelas MergablePropertyAttribute.

Bidang

Default

Menentukan nilai default, yaitu Yes, yang merupakan properti dapat dikombinasikan dengan properti milik objek lain di jendela Properti. Bidang ini static bersifat baca-saja.

No

Menentukan bahwa properti tidak dapat digabungkan dengan properti milik objek lain dalam jendela Properti. Bidang ini static bersifat baca-saja.

Yes

Menentukan bahwa properti dapat digabungkan dengan properti milik objek lain dalam jendela Properti. Bidang ini static bersifat baca-saja.

Properti

AllowMerge

Mendapatkan nilai yang menunjukkan apakah properti ini dapat digabungkan dengan properti milik objek lain di jendela Properti.

TypeId

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

(Diperoleh dari Attribute)

Metode

Equals(Object)

Menunjukkan apakah instans ini dan objek tertentu sama.

GetHashCode()

Mengembalikan kode hash untuk instans ini.

GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Menentukan apakah atribut ini adalah default.

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

Lihat juga