Skip to content

Commit

Permalink
Allow field-targeted attributes on auto-property declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
RexJaeschke authored Apr 17, 2021
1 parent edfe37a commit 64caca6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,32 @@ public class ReadOnlyPoint {
}
```
Although the backing field is hidden, that field may have field-targeted attributes applied directly to it via the automatically implemented property's *property_declaration* ([§15.7.1](classes.md#1571-general)).
> *Example*: The following code
> ```csharp
> public class Foo
> {
> [field: NonSerialized]
> public string MySecret { get; set; }
> }
> ```
> results in the field-targeted attribute `NonSerialized` being applied to the compiler-generated backing field, as if the code had been written as follows:
> ```csharp
> [Serializable]
> public class Foo
> {
> [NonSerialized]
> private string _mySecretBackingField;
> public string MySecret
> {
> get { return _mySecretBackingField; }
> set { _mySecretBackingField = value; }
> }
> }
> ```
> *end example*
### 15.7.5 Accessibility
If an accessor has an *accessor_modifier*, the accessibility domain ([§8.5.3](basic-concepts.md#853-accessibility-domains)) of the accessor is determined using the declared accessibility of the *accessor_modifier*. If an accessor does not have an *accessor_modifier*, the accessibility domain of the accessor is determined from the declared accessibility of the property or indexer.
Expand Down

0 comments on commit 64caca6

Please sign in to comment.