この属性が関連付けられているプロパティが読み取り専用かどうかを示す値を取得します。
名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文
'宣言
Public ReadOnly Property IsReadOnly As Boolean
'使用
Dim instance As ReadOnlyAttribute
Dim value As Boolean
value = instance.IsReadOnly
public bool IsReadOnly { get; }
public:
property bool IsReadOnly {
bool get ();
}
/** @property */
public boolean get_IsReadOnly ()
public function get IsReadOnly () : boolean
プロパティ値
この属性が関連付けられているプロパティが読み取り専用の場合は true。プロパティが読み書き可能の場合は false。
使用例
MyProperty
が読み取り専用かどうかを確認するコード例を次に示します。最初に、次を実行することによって、MyProperty
の属性を取得します。
オブジェクトのすべてのプロパティを保持する PropertyDescriptorCollection を取得します。
PropertyDescriptorCollection にインデックスを付けて、
MyProperty
を取得します。プロパティの属性を属性変数に格納します。
次に、myAttribute
を AttributeCollection にある ReadOnlyAttribute の値に設定し、プロパティが読み取り専用かどうかを確認します。
' 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
// 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.
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).
get_Item("MyProperty").get_Attributes();
// Checks to see whether the property is read-only.
ReadOnlyAttribute myAttribute = ((ReadOnlyAttribute)
(attributes.get_Item(ReadOnlyAttribute.class.ToType())));
if (myAttribute.get_IsReadOnly()) {
// Insert code here.
}
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
参照
関連項目
ReadOnlyAttribute クラス
ReadOnlyAttribute メンバ
System.ComponentModel 名前空間
ReadOnlyAttribute クラス
Attribute
PropertyDescriptor クラス
AttributeCollection クラス
PropertyDescriptorCollection クラス