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
Is there any way we could make use of CallerArgumentExpressionAttribute? #3936
Comments
We cannot do this with breaking binary compatibility, but the attribute is only effective at compile time anyhow.
We can replace the first with:
It will not be confused with the 2nd. Similar like |
Problem is that existing code like that: Assert.True(myCondition, "MyCondition should certainly be true!"); will pick up the first method now.
|
Which is correct. The CallerArgumentExpression only evaluates to the condition string when not specified, otherwise it will be the value passed as an argument:
Gives:
Based on the following dummy class:
|
Problem is that existing method usages rarely provide Assert.True(myCondition, "MyCondition should be true when the sky is blue!"); it will print
which is probably not what's expected. |
Yes, this only helps where there was no message given previously. |
This one helps with your situation:
This however will conflict in one case with the Potentially this can be detected by scanning for '{0' in the string. |
This would be a really great feature to have. Is there any option to do this ourselves? |
C#10 has a nice addition of CallerArgumentExpressionAttribute, which we could use to print
actual
argument expression in error messages.I can see two problems though:
string
parameter to methods. But we already have overloads withmessage
string parameter.params
parameter. And we can't combineparams
and optional parameters in the same method.Is there any way we could make use of this attribute?
The text was updated successfully, but these errors were encountered: