{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/8457","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/8457/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/8457/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/8457/events","html_url":"https://github.com/dotnet/roslyn/issues/8457","id":132178155,"number":8457,"title":"Proposal:  Simplified Property Patterns","user":{"login":"HaloFour","id":10102290,"avatar_url":"https://avatars.githubusercontent.com/u/10102290?v=3","gravatar_id":"","url":"https://api.github.com/users/HaloFour","html_url":"https://github.com/HaloFour","followers_url":"https://api.github.com/users/HaloFour/followers","following_url":"https://api.github.com/users/HaloFour/following{/other_user}","gists_url":"https://api.github.com/users/HaloFour/gists{/gist_id}","starred_url":"https://api.github.com/users/HaloFour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HaloFour/subscriptions","organizations_url":"https://api.github.com/users/HaloFour/orgs","repos_url":"https://api.github.com/users/HaloFour/repos","events_url":"https://api.github.com/users/HaloFour/events{/privacy}","received_events_url":"https://api.github.com/users/HaloFour/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"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2016-02-08T15:47:49Z","updated_at":"2016-02-25T02:45:38Z","closed_at":null,"body":"I had mentioned this in #206 but I wanted to open a separate proposal to consider it.  In my opinion the current syntax for property patterns can be a little weird looking given that the properties are matched to subpatterns.  I think that it would be easier to read to have simpler syntax for the simple cases.\r\n\r\n#### Constant Pattern\r\n\r\nThe constant pattern can be compared using the equality operator instead of `is`.  There is no real improvement to verbosity here but it appears to look more like a normal comparison.  The same rules apply in that the operand must be a constant.\r\n\r\n```cs\r\nif (obj is Person { LastName == \"Gates\" }) { ... }\r\n\r\n// equivalent to\r\nif (obj is Person { LastName is \"Gates\" }) { ... }\r\n```\r\n\r\n#### Variable Pattern\r\n\r\nThe variable pattern looks more like an inline variable declaration and should feel immediately familiar.\r\n\r\n```cs\r\nif (obj is Person { var lastName = LastName }) {\r\n    Console.WriteLine($\"Hello Mr. {lastName}\");\r\n}\r\n\r\n// equivalent to\r\nif (obj is Person { LastName is var lastName }) {\r\n    Console.WriteLine($\"Hello Mr. {lastName}\");\r\n}\r\n```\r\n\r\n#### Inline Guards\r\n\r\nInline guards allow to put simple comparison logic directly into the property pattern without having to use the variable pattern combined with `when` guard clauses.\r\n\r\n```cs\r\nstring lastName = \"Gates\";\r\nif (obj is Person { LastName == lastName, Age >= 60 }) { ... }\r\n\r\n// equivalent to\r\nstring lastName = \"Gates\";\r\nif (obj is Person { LastName is var $tmp0, Age is var $tmp1 }\r\n    when $tmp0 == lastName && $tmp1 >= 60) { ... } \r\n```\r\n\r\nPossibly also support inline `bool` expressions:\r\n\r\n```cs\r\nstring pattern = \"(?i)(Gates|Ballmer|Nadella)\";\r\nif (obj is Person { Regex.Matches(LastName, pattern) }) { ... }\r\n\r\n// equivalent to\r\nif (obj is Person { LastName is var $tmp0 } when Regex.Matches($tmp0, pattern)) { ... }\r\n```\r\n\r\n#### Known Type\r\n\r\nCan omit the type name and the compiler will perform the property pattern using the known type.\r\n\r\n```cs\r\nPerson person = ...;\r\nif (person is { LastName == \"Gates\", var firstName = FirstName }) { ... }\r\n\r\n// equivalent to\r\nif (obj is Person { LastName is \"Gates\", FirstName is var firstName }) { ... }\r\n```"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/188574398","html_url":"https://github.com/dotnet/roslyn/issues/8457#issuecomment-188574398","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/8457","id":188574398,"user":{"login":"HaloFour","id":10102290,"avatar_url":"https://avatars.githubusercontent.com/u/10102290?v=3","gravatar_id":"","url":"https://api.github.com/users/HaloFour","html_url":"https://github.com/HaloFour","followers_url":"https://api.github.com/users/HaloFour/followers","following_url":"https://api.github.com/users/HaloFour/following{/other_user}","gists_url":"https://api.github.com/users/HaloFour/gists{/gist_id}","starred_url":"https://api.github.com/users/HaloFour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HaloFour/subscriptions","organizations_url":"https://api.github.com/users/HaloFour/orgs","repos_url":"https://api.github.com/users/HaloFour/repos","events_url":"https://api.github.com/users/HaloFour/events{/privacy}","received_events_url":"https://api.github.com/users/HaloFour/received_events","type":"User","site_admin":false},"created_at":"2016-02-25T02:45:38Z","updated_at":"2016-02-25T02:45:38Z","body":"@paulomorgado Within the property pattern that identifier would refer specifically to the property.  Any other identifier by that name in scope wouldn't matter."}}