Allow a tuple of const types to be a const #8332
Unanswered
seanblue
asked this question in
Language Ideas
Replies: 2 comments
-
See: #1979 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I swear I looked around before posting this 🙈 @HaloFour Would my proposal of allowing tuples to be consts effectively be one possible implementation of that previous issue "Allow tuples as attribute parameters"? I did expect changes outside of C# language to be needed (as you mentioned in that other issue), but do you have any thoughts on the complexity? |
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
-
In short, I'd like to be able to take types that can individually be
const
and wrap them up in a tuple, then treat that tuple as aconst
as well. For example, in addition toThe following would be allowed
The above example is obviously contrived and fairly useless, so that's just to make clear what I mean. My main use case would be in unit testing. Let's say I have a test with some combinatorial testing via the NUnit
Values
attribute.There are times when I want to add another test parameter, but it's actually two values coupled together, e.g. an input of some
decimal
and then the rounded value as the test expectation. If these were the only parameters I would doBut if I want to do this along with the previous combinatorial cases, it quickly blows up in size using
TestCase
. It also results in a lot of data duplication, not to mention the loss of automatically testing enum values added later whichValues
gives for free.Of course, another way to do this currently would be using
TestCaseSource
, but this can also be combersome.Instead, I'd like to be able to use
const
tuples to do the following(It would be more convenient if the tuple could immediately be deconstructed into multiple named params like JavaScript allows, but even without this the main goal would be achieved.)
This is currently not possible since tuples cannot be treated as constants. I'm honestly not sure of any use cases outside of unit testing, but if anyone has another use case please mention. Besides that, does anyone know how feasible/complex this would be to implement into C#?
Beta Was this translation helpful? Give feedback.
All reactions