ReadOnlyAttribute.IsReadOnly 属性     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示该特性绑定到的属性是否为只读属性。
public:
 property bool IsReadOnly { bool get(); };public bool IsReadOnly { get; }member this.IsReadOnly : boolPublic ReadOnly Property IsReadOnly As Boolean属性值
如果该特性所绑定到的属性为只读属性,则为 true;如果该属性为读/写属性,则为 false。
示例
下面的代码示例检查是否 MyProperty 为只读。 首先,代码通过执行以下操作获取 的属性 MyProperty :
- 检索 PropertyDescriptorCollection 具有 对象的所有属性的 。 
- 索引到 中 PropertyDescriptorCollection 以获取 - MyProperty。
- 将此属性的属性保存在 attributes 变量中。 
然后,代码将 设置为 myAttribute 中 AttributeCollection 的值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