{"action":"opened","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1607","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1607/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1607/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1607/events","html_url":"https://github.com/dotnet/csharplang/issues/1607","id":329794266,"node_id":"MDU6SXNzdWUzMjk3OTQyNjY=","number":1607,"title":"Required in properties ","user":{"login":"cordasfilip","id":6892233,"node_id":"MDQ6VXNlcjY4OTIyMzM=","avatar_url":"https://avatars1.githubusercontent.com/u/6892233?v=4","gravatar_id":"","url":"https://api.github.com/users/cordasfilip","html_url":"https://github.com/cordasfilip","followers_url":"https://api.github.com/users/cordasfilip/followers","following_url":"https://api.github.com/users/cordasfilip/following{/other_user}","gists_url":"https://api.github.com/users/cordasfilip/gists{/gist_id}","starred_url":"https://api.github.com/users/cordasfilip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cordasfilip/subscriptions","organizations_url":"https://api.github.com/users/cordasfilip/orgs","repos_url":"https://api.github.com/users/cordasfilip/repos","events_url":"https://api.github.com/users/cordasfilip/events{/privacy}","received_events_url":"https://api.github.com/users/cordasfilip/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-06T09:45:09Z","updated_at":"2018-06-06T09:45:09Z","closed_at":null,"author_association":"NONE","body":"This is an idea I had in another [thread](https://github.com/dotnet/csharplang/issues/1087) but I think it could be useful for other things as well .\r\nSomething I always liked are Object Initializers but they become unusable when working with immutable objects and there is no way to force the user of the class to set the property. We could indicate that the property must be used in Object Initializer with in parameter.So if we define a class like this.\r\n\r\n```\r\npublic class Test\r\n{\r\n    public in string Prop1 { get; set; }\r\n\r\n    private in string Prop2 { get; set; }\r\n\r\n    public in string Prop3 { get; private set; }\r\n\r\n    public in string Prop4 { get; }\r\n}\r\n\r\nstatic void Main(string[] args)\r\n{\r\n    var t1 = new Test(); // Compile time error\r\n    var t2 = new Test\r\n    {\r\n        Prop1 = \"\",\r\n        Prop2 = \"\",\r\n        Prop3 = \"\",\r\n        Prop4 = \"\"\r\n    };// No error even if we have private fields\r\n\r\n}\r\n```\r\nTo me this solves two problems with one solution. Makes object initializers work for immutable classes and DI injection could easily fill only the in properties. We would get compile time errors if no property is set and the build will fail if someone change something. This doesn't need to be run-time error really and if someone dose something he was not suppose to let him handle it on his own risk. Since this are just properties everything will work as it dose now with inheritance and partial...\r\nI also think this will be useful for null-able reference types since I don't know how properties will work if you don't have default values for properties, this way you could make a none null-able reference type as in and let the user of the class have to deal with it when creating a new object. "}}
{"actor":{"display_login":"cordasfilip"}}