{"action":"closed","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/14372","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/14372/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/14372/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/14372/events","html_url":"https://github.com/dotnet/roslyn/issues/14372","id":181771023,"number":14372,"title":"Proposal: Overridable is operator","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},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-07T21:25:43Z","updated_at":"2016-10-08T19:35:00Z","closed_at":"2016-10-08T19:35:00Z","body":"Disclaimer: This is not related to the previously proposed `is` operator for deconstruction.\r\n\r\nSwift has introduced a \"match\" operator to override matching logic for types. I think it is useful to have something similar to [the `~=` operator in Swift](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Patterns.html) (via the `is` operator).\r\n\r\nThe overridable `is` operator will accept precisely two operands.\r\n\r\nUsing #11159:\r\n```cs\r\n[Flags]\r\nenum State { None, A = 1, B = 2, C = 4 }\r\n\r\nextension class StateExtensions : State {\r\n  public static bool operator is(State a, State b) => a.HasFlag(b);\r\n}\r\n\r\nState s = State.A | State.B;\r\nConsole.WriteLine(s is State.A); // prints true\r\n// translates to\r\nConsole.WriteLine(StateExtensions.op_Match(s, State.A));\r\n\r\n```\r\nClearly, the logic is different compared to `==` so we need to define it as the `is` operator.\r\n\r\nWith help of #262 and #2944 we *might* be able to generalize the above example.\r\n```cs\r\npublic extension class FlagsEnumExtensions<T> : T where T : enum, [Flags] {\r\n  public static bool operator is(T a, T b) => a.HasFlag(b);\r\n}\r\n```\r\nThe advantage of this approach is that you can have custom matching logic also in `switch` statements."}}
{"actor":{"display_login":"alrz"}}