ReadOnlyAttribute.IsReadOnly Свойство

Определение

Возвращает значение, указывающее, привязано ли свойство к этому атрибуту только для чтения.

public:
 property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean

Значение свойства

Значение , если свойство, к этому атрибуту привязано только для чтения; Значение , если свойство считывается или записывается.

Примеры

В следующем примере кода проверяется, доступен ли MyProperty доступ только для чтения. Во-первых, код получает атрибуты для MyProperty выполнения следующих действий:

  • PropertyDescriptorCollection Получение объекта со всеми свойствами.

  • Индексирование в PropertyDescriptorCollection получение MyProperty.

  • Сохранение атрибутов для этого свойства в переменной атрибутов.

Затем код задает myAttribute значение ReadOnlyAttribute в элементе 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

Применяется к

См. также раздел