DesignerSerializationVisibilityAttribute.Visibility Eigenschaft

Definition

Ruft einen Wert ab, der den grundlegenden Serialisierungsmodus angibt, den ein Serialisierungsprogramm verwenden soll, wenn bestimmt wird, ob und wie der Wert einer Eigenschaft beibehalten wird.

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

Eigenschaftswert

Einer der DesignerSerializationVisibility-Werte. Der Standardwert ist Visible.

Beispiele

Im folgenden Codebeispiel wird gezeigt, wie der Wert von für MyPropertyüberprüft wirdDesignerSerializationVisibilityAttribute. Zuerst ruft der Code eine PropertyDescriptorCollection mit allen Eigenschaften für das -Objekt ab. Als Nächstes wird der Code indiziert PropertyDescriptorCollection , um abzurufen MyProperty. Anschließend gibt der Code die Attribute für diese Eigenschaft zurück und speichert sie in der Attributvariablen.

In diesem Beispiel werden zwei verschiedene Möglichkeiten zum Überprüfen des Werts von dargestellt DesignerSerializationVisibilityAttribute. Im zweiten Codefragment ruft das Beispiel die Equals -Methode mit einem -Wert auf static . Im letzten Codefragment wird im Beispiel die Visibility -Eigenschaft verwendet, um den Wert zu überprüfen.

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

Gilt für:

Weitere Informationen