DesignerSerializationVisibilityAttribute.Visibility Propriedade

Definição

Obtém um valor que indica o modo básico de serialização que um serializador deve usar ao determinar se e como persistir o valor de uma propriedade.

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

Valor de Propriedade

Um dos DesignerSerializationVisibility valores. A predefinição é Visible.

Exemplos

O seguinte exemplo de código mostra como verificar o valor do DesignerSerializationVisibilityAttribute para MyProperty. Primeiro, o código recebe uma PropertyDescriptorCollection com todas as propriedades do objeto. De seguida, o código indexa-se para obter PropertyDescriptorCollectionMyProperty. Depois, o código devolve os atributos dessa propriedade e guarda-os na variável de atributos.

Este exemplo apresenta duas formas diferentes de verificar o valor do DesignerSerializationVisibilityAttribute. No segundo fragmento de código, o exemplo chama o Equals método com um static valor. No último fragmento de código, o exemplo usa a Visibility propriedade para verificar o valor.

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

Aplica-se a

Ver também