-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Proposal: Lambda Patterns #8990
Comments
What would lamba patters be used for? |
@orthoxerox Instead of any expression tree inspection that you currently need to write by hand or perhaps more verbosely with property patterns, as the final translation suggests. |
I like the idea, inspecting expression trees in API codes can be painful in both writing and reading. Maybe the title should be expression trees instead of lambda? |
@DiryBoy Had the same thought. I don't mind the title but it seems a lambda that is a pattern, right? Because expression tree pattern could be confusing as the hypothetical translation suggests, you still can match expression tree types via property patterns. |
Right, so please forget about the title change:) |
What I don't like about this is that it introduces quite a heavy new syntax, but that syntax is useful only in pretty niche situations. I think that pattern matching expression trees could work pretty well using some well-written switch (expr.Body) {
case Member(*, "Length"): break;
case Member(*, string member): break;
}
switch (expr.Body) {
case MethodCall(*, "IndexOf", { Constant("foo") }): break;
case MethodCall(*, "IndexOf", { Constant(string param) }): break;
} |
Currently C# has a nice homoiconicity between expressions and delegates (aka expression trees). I want to suggest to bring that to patterns as well via lambdas.
Arguments
I'm using list patterns, proposed in Proposal: List, Indexer (Dictionary) and String Patterns #5811.x
is inferred from the targetexpr
.Expression
property must be aParameterExpression
.The text was updated successfully, but these errors were encountered: