strong typed CallerAttributes like CallerMemberName CallerArgumentExpression #7845
Replies: 3 comments
-
Generally in BCL we do not use the pattern to create alias for primitive types.
This can easily be supported by an analyzer with warning. |
Beta Was this translation helpful? Give feedback.
-
I guess that part is true, but the case where we have to resolve the correct overload isn't solved.
|
Beta Was this translation helpful? Give feedback.
-
This would be very difficult to solve entirely due to backwards compatibility with existing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background and motivation
I have to create a couple of methods that require me to know the CallerMemberName and CallerArgumentExpressions. But because those are all just strings I might be calling an unintended wrong overloads as they are implemented with a string parameter.
Suppose I have:
I guess the same holds for CallerArgumentExpresssion
API Proposal
To prevent all those incorrect calls I propose using strong type parameters that just behave as string but prevent these issues.
I would like to make it clear it is intentional:
such that:
will call the correct overloads because the callermembername is strong typed.
where we have a predefined types/structs
And for argumentexpression use the same approach, and others like CallerLineNumberAttribute
API Usage
Using it is pretty straight forward, use the strong type.
E.g.
Alternative Designs
No response
Risks
Make it work backwards compatible and show a message or warning if the new API is not used. It will help people from making mistakes.
Beta Was this translation helpful? Give feedback.
All reactions