DesignerSerializationVisibilityAttribute.Visibility Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan nilai yang menunjukkan mode serialisasi dasar yang harus digunakan serializer saat menentukan apakah dan cara mempertahankan nilai properti.
public:
property System::ComponentModel::DesignerSerializationVisibility Visibility { System::ComponentModel::DesignerSerializationVisibility get(); };
public System.ComponentModel.DesignerSerializationVisibility Visibility { get; }
member this.Visibility : System.ComponentModel.DesignerSerializationVisibility
Public ReadOnly Property Visibility As DesignerSerializationVisibility
Nilai Properti
Salah DesignerSerializationVisibility satu nilai. Default adalah Visible.
Contoh
Contoh kode berikut menunjukkan cara memeriksa nilai DesignerSerializationVisibilityAttribute untuk MyProperty
. Pertama kode mendapatkan PropertyDescriptorCollection dengan semua properti untuk objek . Selanjutnya, kode mengindeks ke PropertyDescriptorCollection dalam untuk mendapatkan MyProperty
. Kemudian, kode mengembalikan atribut untuk properti ini dan menyimpannya dalam variabel atribut.
Contoh ini menyajikan dua cara berbeda untuk memeriksa nilai DesignerSerializationVisibilityAttribute. Dalam fragmen kode kedua, contoh memanggil Equals metode dengan static
nilai . Dalam fragmen kode terakhir, contoh menggunakan Visibility 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 DesignerSerializationVisibilityAttribute is set to Content.
if ( attributes[ DesignerSerializationVisibilityAttribute::typeid ]->Equals( DesignerSerializationVisibilityAttribute::Content ) )
{
// Insert code here.
}
// This is another way to see whether the property is marked as serializing content.
DesignerSerializationVisibilityAttribute^ myAttribute = dynamic_cast<DesignerSerializationVisibilityAttribute^>(attributes[ DesignerSerializationVisibilityAttribute::typeid ]);
if ( myAttribute->Visibility == DesignerSerializationVisibility::Content )
{
// Insert code here.
}
// Gets the attributes for the property.
AttributeCollection attributes =
TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
// Checks to see if the value of the DesignerSerializationVisibilityAttribute is set to Content.
if(attributes[typeof(DesignerSerializationVisibilityAttribute)].Equals(DesignerSerializationVisibilityAttribute.Content)) {
// Insert code here.
}
// This is another way to see whether the property is marked as serializing content.
DesignerSerializationVisibilityAttribute myAttribute =
(DesignerSerializationVisibilityAttribute)attributes[typeof(DesignerSerializationVisibilityAttribute)];
if(myAttribute.Visibility == DesignerSerializationVisibility.Content) {
// 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 DesignerSerializationVisibilityAttribute
' is set to Content.
If attributes(GetType(DesignerSerializationVisibilityAttribute)).Equals( _
DesignerSerializationVisibilityAttribute.Content) Then
' Insert code here.
End If
' This is another way to see whether the property is marked as serializing content.
Dim myAttribute As DesignerSerializationVisibilityAttribute = _
CType(attributes(GetType(DesignerSerializationVisibilityAttribute)), _
DesignerSerializationVisibilityAttribute)
If myAttribute.Visibility = DesignerSerializationVisibility.Content Then
' Insert code here.
End If