Partilhar via


DesignerSerializationVisibilityAttribute.Visibility Propriedade

Definição

Obtém um valor que indica o modo de serialização básico 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 da propriedade

Um dos DesignerSerializationVisibility valores. O padrão é Visible.

Exemplos

O exemplo de código a seguir mostra como verificar o valor do DesignerSerializationVisibilityAttribute .MyProperty Primeiro, o código obtém uma PropertyDescriptorCollection com todas as propriedades do objeto. Em seguida, o código indexa no PropertyDescriptorCollection para obter MyProperty. Em seguida, o código retorna os atributos dessa propriedade e os salva na variável de atributos.

Este exemplo apresenta duas maneiras 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

Confira também