{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/8713","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/8713/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/8713/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/8713/events","html_url":"https://github.com/dotnet/roslyn/issues/8713","id":133703283,"number":8713,"title":"Proposal: Property implementation interface and syntax for complex logics","user":{"login":"lachbaer","id":17041498,"avatar_url":"https://avatars.githubusercontent.com/u/17041498?v=3","gravatar_id":"","url":"https://api.github.com/users/lachbaer","html_url":"https://github.com/lachbaer","followers_url":"https://api.github.com/users/lachbaer/followers","following_url":"https://api.github.com/users/lachbaer/following{/other_user}","gists_url":"https://api.github.com/users/lachbaer/gists{/gist_id}","starred_url":"https://api.github.com/users/lachbaer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lachbaer/subscriptions","organizations_url":"https://api.github.com/users/lachbaer/orgs","repos_url":"https://api.github.com/users/lachbaer/repos","events_url":"https://api.github.com/users/lachbaer/events{/privacy}","received_events_url":"https://api.github.com/users/lachbaer/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":"2016-02-15T12:44:51Z","updated_at":"2016-02-16T16:52:48Z","closed_at":null,"body":"## Background\r\nDuring the discussion of Property-scoped fields (#850) there came the question by the assigned implementor whether to allow also property scoped classes, methods, etc. I do not think that this is a good idea with respect to the layout of code, and that it is probably better to put more complex logic, that needs additional methods and internal classes into extra classes.\r\n\r\nBut maybe it is a good idea to have a default, framework carried way to support this approach.\r\n\r\n## Implementation\r\nFirst of all we need a new abstract framework class\r\n```C#\r\n    public interface IPropertyAccessors<T>\r\n    {\r\n        T GetValue();\r\n        void SetValue(T value);\r\n    }\r\n```\r\nthen you can implement an accessor class\r\n```C#\r\n    internal class MyPropertyLogic<T> : IPropertyAccessors<T>\r\n    {\r\n        T _backingField;\r\n        public T GetValue()\r\n        {  /* my very complicated getter logic */   }\r\n\r\n        public void SetValue(T value)\r\n        {  /* my even more complicated setter logic */   }\r\n\r\n        // add some more very complex methods, properties, fields, nested classes, etc...\r\n    }\r\n```\r\n**now comes the thrilling part** - how can you use that self-written-complicated-accessor-class?\r\n```C#\r\n    class A {\r\n        public int Prop : MyPropertyLogic<int> { get; private set; }\r\n    }\r\n```\r\nLet me suffocate some arguments before the discussion starts:\r\n* Many language features already rely on framework support. `using` needs `IDisposable`, LINQ even requires a new framework version. So I see no reason, why this would be different.\r\n* The new, divergent property declaration seems fine to me, even if I only had a rough understanding of the language: 1. it looks like a property (no `()` after the identifier, no additional keyword like `class` or `interface`); 2. it seems to have a public getter, but only a private setter; 3. seems that it inherits (it's logic) from somewhere.\r\n* Implementation by the compiler can be done like\r\n```C#\r\n    class A {\r\n        // the compiler actually names the backing field <MyPropertyLogic>k__backingField;\r\n        public int Prop {\r\n            IPropertyAccessors<int> k__backing = new MyPropertyLogic<int>(); // #850 syntax\r\n            get => k__backing.GetValue();   // #7881 syntax\r\n            set => k__backing.SetValue(value);   // #7881 syntax\r\n        }\r\n    }\r\n```\r\nSome requirements must be met for this syntax:\r\n* The implementing logic class must have a public parameterless constructor\r\n* The generic interface type parameter is of the type of the property\r\n* In cases like above, where the implementing class is generic, the coder has to take care of the correct type parameters in the inheritance part after the `:` colon.\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/184766353","html_url":"https://github.com/dotnet/roslyn/issues/8713#issuecomment-184766353","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/8713","id":184766353,"user":{"login":"alrz","id":3105979,"avatar_url":"https://avatars.githubusercontent.com/u/3105979?v=3","gravatar_id":"","url":"https://api.github.com/users/alrz","html_url":"https://github.com/alrz","followers_url":"https://api.github.com/users/alrz/followers","following_url":"https://api.github.com/users/alrz/following{/other_user}","gists_url":"https://api.github.com/users/alrz/gists{/gist_id}","starred_url":"https://api.github.com/users/alrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alrz/subscriptions","organizations_url":"https://api.github.com/users/alrz/orgs","repos_url":"https://api.github.com/users/alrz/repos","events_url":"https://api.github.com/users/alrz/events{/privacy}","received_events_url":"https://api.github.com/users/alrz/received_events","type":"User","site_admin":false},"created_at":"2016-02-16T16:52:48Z","updated_at":"2016-02-16T16:52:48Z","body":"Yeah, as long as you don't have to deal with UI which is mutable by nature. C# has to deal with it anyway, because it is meant to be used to write UI applications."}}