ReadOnlyAttribute.IsReadOnly 属性

定义

获取一个值,该值指示该特性绑定到的属性是否为只读属性。

public:
 property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean

属性值

如果该特性所绑定到的属性为只读属性,则为 true;如果该属性为读/写属性,则为 false

示例

下面的代码示例检查是否 MyProperty 为只读。 首先,代码通过执行以下操作获取 的属性 MyProperty

然后,代码将 设置为 myAttributeAttributeCollection 的值ReadOnlyAttribute,并检查 属性是否为只读。

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes;

// Checks to see whether the property is read-only.
ReadOnlyAttribute^ myAttribute = dynamic_cast<ReadOnlyAttribute^>(attributes[ ReadOnlyAttribute::typeid ]);
if ( myAttribute->IsReadOnly )
{
   // Insert code here.
}
// Gets the attributes for the property.
AttributeCollection attributes = 
   TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

// Checks to see whether the property is read-only.
ReadOnlyAttribute myAttribute = 
   (ReadOnlyAttribute)attributes[typeof(ReadOnlyAttribute)];

if(myAttribute.IsReadOnly) {
   // Insert code here.
}
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
   TypeDescriptor.GetProperties(Me)("MyProperty").Attributes
       
' Checks to see whether the property is read-only.
Dim myAttribute As ReadOnlyAttribute = _
   CType(attributes(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
   
If myAttribute.IsReadOnly Then
    ' Insert code here.
End If

适用于

另请参阅