{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/7678","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/7678/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/7678/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/7678/events","html_url":"https://github.com/dotnet/roslyn/issues/7678","id":123667319,"number":7678,"title":"Proposal: auto property backing field reference resolving when used as ref and out arguments","user":{"login":"m0sa","id":503702,"avatar_url":"https://avatars.githubusercontent.com/u/503702?v=3","gravatar_id":"","url":"https://api.github.com/users/m0sa","html_url":"https://github.com/m0sa","followers_url":"https://api.github.com/users/m0sa/followers","following_url":"https://api.github.com/users/m0sa/following{/other_user}","gists_url":"https://api.github.com/users/m0sa/gists{/gist_id}","starred_url":"https://api.github.com/users/m0sa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m0sa/subscriptions","organizations_url":"https://api.github.com/users/m0sa/orgs","repos_url":"https://api.github.com/users/m0sa/repos","events_url":"https://api.github.com/users/m0sa/events{/privacy}","received_events_url":"https://api.github.com/users/m0sa/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Discussion","name":"Discussion","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-12-23T14:20:55Z","updated_at":"2016-03-10T08:44:03Z","closed_at":null,"body":"It would be great if auto properties would automatically reslove to their backing filed, allowing us to pass them to methods as ref and out arguments:\r\n\r\n```csharp\r\npublic class Foo\r\n{ \r\n     public int Bar { get; set; }\r\n     public void Test(string str)\r\n     {\r\n          int.TryParse(str, out Bar);\r\n     }\r\n\r\n     public int Baz { get; } // readonly\r\n     public Foo(string str) // ctor\r\n     {\r\n          int.TryParse(str, out Baz); // Bar = 1  would also get translated in <Bar_backingField> = 1\r\n     }   \r\n}\r\n```\r\n\r\nthis proposal is about making the private backing fields available, as it is already the case with setters for read-only properties in the constructor. The code above should be equivalent to:\r\n\r\n```csharp\r\npublic class Foo\r\n{\r\n     private int _bar;\r\n     public int Bar { get { return _bar; } set { _bar = value; } }\r\n     public void Test(string str)\r\n     {\r\n          int.TryParse(str, out _bar);\r\n     }\r\n\r\n     private readonly int _baz;\r\n     public int Baz { get { return _baz;  }\r\n     public Foo(string str) // ctor\r\n     {\r\n          int.TryParse(str, out _baz);\r\n     }   \r\n}\r\n```\r\n...and thus only work inside the class declaring the property.\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/194738175","html_url":"https://github.com/dotnet/roslyn/issues/7678#issuecomment-194738175","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/7678","id":194738175,"user":{"login":"ViIvanov","id":795200,"avatar_url":"https://avatars.githubusercontent.com/u/795200?v=3","gravatar_id":"","url":"https://api.github.com/users/ViIvanov","html_url":"https://github.com/ViIvanov","followers_url":"https://api.github.com/users/ViIvanov/followers","following_url":"https://api.github.com/users/ViIvanov/following{/other_user}","gists_url":"https://api.github.com/users/ViIvanov/gists{/gist_id}","starred_url":"https://api.github.com/users/ViIvanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ViIvanov/subscriptions","organizations_url":"https://api.github.com/users/ViIvanov/orgs","repos_url":"https://api.github.com/users/ViIvanov/repos","events_url":"https://api.github.com/users/ViIvanov/events{/privacy}","received_events_url":"https://api.github.com/users/ViIvanov/received_events","type":"User","site_admin":false},"created_at":"2016-03-10T08:44:03Z","updated_at":"2016-03-10T08:44:03Z","body":"Just for me, adding an ampersand (for example) before a name of the auto-property for reference to the backing field is better than implicit referencing in ref/out context:\r\n```cs\r\npublic class Foo\r\n{\r\n    public int Bar { get; }  \r\n    public Foo(string bar) { int.TryParse(bar, out &Bar); }\r\n}\r\n```\r\nMay be, ampersand should be changed to something else, because in unsafe context it not obvious."}}