The option to conditionally include method arguments #9318
Unanswered
bud11
asked this question in
Language Ideas
Replies: 2 comments 11 replies
-
How would it work across assemblies? Usually libraries are shipped only in Release configuration, so the callee's behavior can't be affected by callers configuration. How would the callee deal with the excluded argument? What if it's used in complex expression, or passed as argument of regular method? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I second @huoyaoyuan's questions and add Why are overloads not sufficient to solve this problem? |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem:
In the same way you can use [Conditional("DEBUG")] or similar to exclude a method, while safely removing call sites, I think it'd be helpful if you could exclude particular arguments from a method too.
The obvious use case would be extra method parameters used for debugging. You want these extra method parameters to be constructed and generated and acknowledged, but only in debug builds, or whatever condition you've defined. Otherwise, they don't exist.
The only way I know to do this is with preprocessor if directives right now, but that comes with a lot of boilerplate at the signature and every call site.
Proprosal:
The simplest way I can think of exposing this would be letting you do something like [MethodConditional("DEBUG", 3] - so you have the condition, then the amount of arguments you want to be included from the start. Any further are ignored.
Therefore you would need to keep any conditionally-stripped arguments at the end of the signature, but that seems like a reasonable limitation for the sake of simplicity.
An alternate more flexible idea would be the requirement to supply a string array of the argument names you'd like to include.
Then, any other arguments, both in signature and at call sites, would disappear in builds.
Beta Was this translation helpful? Give feedback.
All reactions