{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1449","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1449/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1449/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1449/events","html_url":"https://github.com/dotnet/csharplang/issues/1449","id":312521929,"node_id":"MDU6SXNzdWUzMTI1MjE5Mjk=","number":1449,"title":"Update several properties of a single object","user":{"login":"JeanCollas","id":3519393,"node_id":"MDQ6VXNlcjM1MTkzOTM=","avatar_url":"https://avatars3.githubusercontent.com/u/3519393?v=4","gravatar_id":"","url":"https://api.github.com/users/JeanCollas","html_url":"https://github.com/JeanCollas","followers_url":"https://api.github.com/users/JeanCollas/followers","following_url":"https://api.github.com/users/JeanCollas/following{/other_user}","gists_url":"https://api.github.com/users/JeanCollas/gists{/gist_id}","starred_url":"https://api.github.com/users/JeanCollas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeanCollas/subscriptions","organizations_url":"https://api.github.com/users/JeanCollas/orgs","repos_url":"https://api.github.com/users/JeanCollas/repos","events_url":"https://api.github.com/users/JeanCollas/events{/privacy}","received_events_url":"https://api.github.com/users/JeanCollas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2018-04-09T13:02:59Z","updated_at":"2018-06-08T03:39:08Z","closed_at":null,"author_association":"NONE","body":"I don't find any way to update several properties of a single object in C# (similar to the with VB statement). \r\nIt may be useful to clarify some mapping functions where several properties has to be updated at once.\r\nHere is a very short example\r\n\r\n        public class MyLink\r\n        {\r\n            public int Id { get; set; }\r\n            public string Name { get; set; }\r\n            public string Description { get; set; }\r\n            public string Link { get; set; }\r\n            public MetaData Meta { get; set; }\r\n            public DateTime? Deleted { get; set; }\r\n        }\r\n        public class MetaData\r\n        {\r\n            public DateTime LastUpdate { get; set; }\r\n            public decimal AvgRate { get; set; }\r\n        }\r\n\r\n\r\n        public void UpdateLink(MyLink link, string name, string description, DateTime lastUpdate)\r\n        {\r\n            link.{\r\n                Name = name,\r\n                Description = description,\r\n                Meta.{\r\n                   LastUpdate = lastUpdate\r\n                }\r\n            };\r\n        }\r\n\r\nAlthough it might induce some recursive conflicts.\r\n\r\nIt can be used following factories calls\r\n\r\n        GetLink(url).{\r\n            Description = description\r\n         }\r\n\r\nOnly a `.`away from what people is already used to:\r\n\r\n        new Link( )\r\n        {\r\n            Name = name\r\n        }\r\n        new Link( ).{\r\n            Name = name\r\n        }\r\n\r\nIt can easily handle null values to avoid exceptions:\r\n\r\n    link?.{\r\n        Name = name\r\n    }  \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/395636598","html_url":"https://github.com/dotnet/csharplang/issues/1449#issuecomment-395636598","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/1449","id":395636598,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NTYzNjU5OA==","user":{"login":"AustinBryan","id":16201886,"node_id":"MDQ6VXNlcjE2MjAxODg2","avatar_url":"https://avatars1.githubusercontent.com/u/16201886?v=4","gravatar_id":"","url":"https://api.github.com/users/AustinBryan","html_url":"https://github.com/AustinBryan","followers_url":"https://api.github.com/users/AustinBryan/followers","following_url":"https://api.github.com/users/AustinBryan/following{/other_user}","gists_url":"https://api.github.com/users/AustinBryan/gists{/gist_id}","starred_url":"https://api.github.com/users/AustinBryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AustinBryan/subscriptions","organizations_url":"https://api.github.com/users/AustinBryan/orgs","repos_url":"https://api.github.com/users/AustinBryan/repos","events_url":"https://api.github.com/users/AustinBryan/events{/privacy}","received_events_url":"https://api.github.com/users/AustinBryan/received_events","type":"User","site_admin":false},"created_at":"2018-06-08T03:39:08Z","updated_at":"2018-06-08T03:39:08Z","author_association":"NONE","body":"Isn't this sort've similar to a `with` keyword in other languages?\r\n\r\n```csharp\r\npublic class MyLink\r\n{\r\n    public string Name        { get; set; }\r\n    public string Description { get; set; }\r\n    public string Link        { get; set; }\r\n    public MetaData Meta      { get; set; }\r\n\r\n    public void DrawLink() { }\r\n}\r\n...\r\npublic void UpdateLink(MyLink link, string name, string description, DateTime lastUpdate)\r\n{\r\n    with link\r\n    {\r\n        Name = name;\r\n        Description = description;\r\n\r\n        with Meta \r\n        {\r\n            LastUpdate = lastUpdate;\r\n        }\r\n\r\n        DrawLink();\r\n    }\r\n}\r\n```\r\n\r\nBasically, the `with` keyword creates a block of code that behaves as if it is a part of that class, allowing you to access the fields and methods directly. It probably shouldn't expose `private` fields and methods, though. \r\n\r\nRegardless of if it uses `.` or `with`, might as well allow the usage of methods inside, right?"}}
{"actor":{"display_login":"AustinBryan"}}