Replies: 1 comment
-
|
This is fixed with C# 14 by allowing default parameters in expression trees |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone
Not sure if anyone else uses this, but we have a serious use case, where we would like to use FluentAssertions within
Expression<>trees.Generally, it shouldn't be a problem, but the use of default values in method calls is not allowed inside Expression trees.
GetTheTree(items => items.Should().Contain(x => x.FirstName == "Name"));Results in a CS0854: An expression tree may not contain a call or invocation that uses optional arguments.
It is due to the optional arguments in
Contain(..., string because = "", params object[] becauseArgs)I see two possible solutions that both have severe downsides:
GetTheTree(items => items.Should()**._()**.Contain(x => x.FirstName == "Name"))After the Should(), we are using the _() to wrap the various Assertion types in our own class, where we can then place new versions of the different methods that do not use default values.
That's also not a nice solution and we would have to define all the overloads to use everything.
Does anyone know a better way around this?
Beta Was this translation helpful? Give feedback.
All reactions