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 덱싱.특성 변수에 이 속성의 특성을 저장합니다.
그런 다음 코드는 해당 AttributeCollection 속성의 ReadOnlyAttribute 값으로 설정하고 myAttribute 속성이 읽기 전용인지 여부를 확인합니다.
// 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