DesignerSerializationVisibilityAttribute.Visibility Eigenschap

Definitie

Hiermee wordt een waarde opgehaald die aangeeft welke basisserialisatiemodus een serialisatiemodus moet gebruiken bij het bepalen of en hoe de waarde van een eigenschap moet worden behouden.

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

Waarde van eigenschap

Een van de DesignerSerializationVisibility waarden. De standaardwaarde is Visible.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u de waarde van de DesignerSerializationVisibilityAttribute for MyPropertykunt controleren. Eerst krijgt de code een PropertyDescriptorCollection met alle eigenschappen voor het object. Vervolgens worden de code-indexen in de PropertyDescriptorCollection code geïndexeert om op te halen MyProperty. Vervolgens retourneert de code de kenmerken voor deze eigenschap en slaat deze op in de kenmerkvariabele.

In dit voorbeeld ziet u twee verschillende manieren om de waarde van de DesignerSerializationVisibilityAttribute. In het tweede codefragment roept het voorbeeld de Equals methode aan met een static waarde. In het laatste codefragment gebruikt het voorbeeld de Visibility eigenschap om de waarde te controleren.

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

Van toepassing op

Zie ook