ReadOnlyAttribute.IsReadOnly Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt een waarde opgehaald die aangeeft of de eigenschap waaraan dit kenmerk is gebonden, alleen-lezen is.
public:
property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean
Waarde van eigenschap
true als de eigenschap waaraan dit kenmerk is gebonden, alleen-lezen is; false als de eigenschap lezen/schrijven is.
Voorbeelden
In het volgende codevoorbeeld wordt gecontroleerd of MyProperty het kenmerk Alleen-lezen is. Eerst haalt de code de kenmerken op MyProperty waarvoor u het volgende doet:
Een met alle eigenschappen voor het object ophalen PropertyDescriptorCollection .
Indexeren in het PropertyDescriptorCollection bestand om op te halen
MyProperty.De kenmerken voor deze eigenschap opslaan in de kenmerkvariabele.
Vervolgens wordt de code ingesteld myAttribute op de waarde van de ReadOnlyAttribute in de AttributeCollection code en wordt gecontroleerd of de eigenschap het kenmerk Alleen-lezen heeft.
// 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