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 and BillWagner committed Apr 3, 2022
1 parent 82f553c commit adcb5cf
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3378,7 +3378,7 @@ An auto-property may optionally have a *property_initializer*, which is applied
> *end example*
<!-- markdownlint-disable MD028 -->
<!-- markdownlint-enablesure MD028 -->
<!-- markdownlint-enable MD028 -->
> *Example*: In the following
>
> ```csharp
Expand Down Expand Up @@ -3417,6 +3417,34 @@ An auto-property may optionally have a *property_initializer*, which is applied
>
> *end example*
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* ([§14.7.1](classes.md#1471-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*
### 14.7.5 Accessibility
If an accessor has an *accessor_modifier*, the accessibility domain ([§7.5.3](basic-concepts.md#753-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 adcb5cf

Please sign in to comment.