Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Field-targeting attributes on auto-properties #7004

Closed
HaloFour opened this issue Nov 24, 2015 · 2 comments
Closed

Proposal: Field-targeting attributes on auto-properties #7004

HaloFour opened this issue Nov 24, 2015 · 2 comments

Comments

@HaloFour
Copy link

This was mentioned on CodePlex but was not implemented in C# 6.0.

I'm proposing allowing field-targeted attributes on auto-properties. The compiler would automatically attach that attribute to the generated backing field.

[field: NonSerialized]
public string Name { get; set; }

equivalent to:

[NonSerialized]
private string name;

public string Name {
    get { return this.name; }
    set { this.name = value; }
}

This would bring auto-properties into parity with events which have supported this syntax since C# 1.0:

[field: NonSerialized]
public event EventHandler Foo;
@alrz
Copy link
Member

alrz commented Nov 24, 2015

It is surprising that it is not already supported! Should be extended on records too

class Foo [Ctor] ([Param][field/property/method/return: Attr] int Value);

for ctor maybe [method: Ctor] class Foo is better.

@jcouv
Copy link
Member

jcouv commented Nov 5, 2017

Language issue was moved to dotnet/csharplang#42
Implementation started for 7.3: #22512

@jcouv jcouv closed this as completed Nov 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants