Minimum number of parameters for params #5477
Replies: 3 comments 27 replies
-
This can be implemented as an analyzer package that defines the attribute and enforces the usage. |
Beta Was this translation helpful? Give feedback.
-
These are well known symbols. I feel like we don't even need an attribute. One could just write a basic analyzer here. That said, I'm skeptical of the value. How often does one call this method and pass no Params? Fellas like it would be caught immediately. |
Beta Was this translation helpful? Give feedback.
-
I have also needed this in the past (enough times to make it worth mentioning), at least a way of saying "You can pass in as many arguments as you like, but you must pass at least one". I have also implemented the workaround of having a regular parameter for the first element and a
I'm not really sure what the correct answer is here, so maybe an analyzer really is the best approach since it's the least invasive to implement. Having said that, I could go on a slightly separate rant about how I so often wish there were types to represent "non-empty" collections in the BCL. |
Beta Was this translation helpful? Give feedback.
-
Can we introduce an attribute or a keyword which stipulates that
params
receives a minimum number of items?Motivation: this is useful for methods like
MakeGenericType
and all the other similar methods, as well as custom code which utilizes these reflection methods; it's impossible to make a generic type/method without at least one type argument.Workaround:
You can see how the workaround has an ugly signature and overhead of allocating another array internally (assuming it's usually needed to have the complete list).
Beta Was this translation helpful? Give feedback.
All reactions