Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CaseOf<T> support for arbitrary types #22

Closed
megafinz opened this issue Jan 27, 2017 · 2 comments
Closed

CaseOf<T> support for arbitrary types #22

megafinz opened this issue Jan 27, 2017 · 2 comments

Comments

@megafinz
Copy link

Is it possible to make General Pattern Matcher to be able to match objects on types apart from values just like Union Pattern Matcher does with it's union cases (via CaseOf)?

abstract class ItemBase { }
class ItemA : ItemBase { }
class ItemB : ItemBase { }
class ItemC : ItemBase { }

ItemBase GetItem() { … }

var item = GetItem();

item.Match()
    .WithType<ItemA>().Do(a => …)
    .WithType<ItemB>().Do(b => …)
    .WithType<ItemC>().Do(c => …)
    .Exec();

I'm not really sure this is constructive, though, because C# 7.0 can pattern match types with the same purpose (via swtich).

@DavidArno
Copy link
Owner

I agree there's little point in implementing this for Match ... Exec statements, as the C# 7 type matching additions to switch would cover this. However, there is likely benefit to adding Match .. Result expression support in the way you describe. We'll have to wait until at least C# v7.1 for the match expression equivalent.

@DavidArno
Copy link
Owner

v2.3.0 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants