ReadOnlyAttribute.IsReadOnly プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
この属性がバインドされているプロパティが読み取り専用かどうかを示す値を取得します。
public:
property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean
プロパティ値
true この属性がバインドされているプロパティが読み取り専用の場合。プロパティが読み取り/書き込みである場合に false します。
例
次のコード例では、 MyProperty が読み取り専用かどうかを確認します。 まず、次の手順を実行して、 MyProperty の属性を取得します。
オブジェクトのすべてのプロパティを含む PropertyDescriptorCollection を取得します。
MyPropertyを取得するためにPropertyDescriptorCollectionにインデックスを作成する。このプロパティの属性を 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