Proposal: Allow switch expressions in expression trees #4821
Answered
by
ufcpp
hazzik
asked this question in
Language Ideas
-
It will be god to be able to use switch expression in expression trees. Expression<Func<int?, string>> i = x => x switch
{
null => "null",
1 => "1",
_ => "default"
}; Expression tree do support var parameter = Expression.Parameter(typeof(int), "x");
var expression = Expression.Lambda<Func<int?, string>>(
Expression.Switch(parameter,
Expression.Constant("default", typeof(string)),
Expression.SwitchCase(
Expression.Constant("null", typeof(string)),
Expression.Constant(null, typeof(int?))),
Expression.SwitchCase(
Expression.Constant("1", typeof(string)),
Expression.Constant(1, typeof(int?)))),
parameter); However |
Beta Was this translation helpful? Give feedback.
Answered by
ufcpp
Jun 11, 2021
Replies: 1 comment 10 replies
-
Beta Was this translation helpful? Give feedback.
10 replies
Answer selected by
333fred
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#158