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

接著程式碼會將 的值ReadOnlyAttributemyAttribute為 ,AttributeCollection並檢查該屬性是否為唯讀。

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

適用於

另請參閱