DesignerSerializationVisibilityAttribute.Visibility 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在決定是否要或是如何保存屬性的值時,取得代表序列化程式所應使用基本序列化模式的值。
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。
範例
下列程式代碼範例示範如何檢查 DesignerSerializationVisibilityAttribute 的值 MyProperty
。 首先,程式代碼會取得 PropertyDescriptorCollection 具有物件之所有屬性的 。 接下來,程式代碼會索引到 PropertyDescriptorCollection ,以取得 MyProperty
。 然後,程式代碼會傳回此屬性的屬性,並將其儲存在屬性變數中。
此範例提供兩種不同的方法來檢查的值 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