DesignerSerializationVisibilityAttribute.Visibility 属性

定义

获取一个值,该值指示序列化程序在确定是否以及如何保持某个属性的值时应使用的基本序列化模式。

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

属性值

DesignerSerializationVisibility 值之一。 默认值为 Visible

示例

下面的代码示例演示如何为 检查 的值DesignerSerializationVisibilityAttributeMyProperty。 首先,代码获取 PropertyDescriptorCollection 具有 对象的所有属性的 。 接下来,代码将索引到 中 PropertyDescriptorCollection 以获取 MyProperty。 然后,代码返回此属性的属性,并将其保存在 attributes 变量中。

此示例提供两种不同的方法来检查 的值DesignerSerializationVisibilityAttribute。 第二个代码片段中,该示例使用 值static调用 Equals 方法。 在最后一个代码片段中,该示例使用 Visibility 属性检查值。

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

适用于

另请参阅