Small feature request for C# 12: scoped using and using static statements. #7238
Replies: 4 comments 3 replies
-
Similar to #2981 (but class scope instead of method scope) |
Beta Was this translation helpful? Give feedback.
-
What happens if there is no feedback on an issue? Is it added to a list somewhere? Or is this taken as an indicator there is insufficient interest in the idea? |
Beta Was this translation helpful? Give feedback.
-
In your example I assume you meant: public void Thing(double[] numbers) {
// Adding the "connecting" definition here makes it completely unambiguous what functions I'm using at the call site.
using static Metric = A.B.C.D.E.F.Metric;
double average = Average(numbers);
double stdDev = StandardDeviation(numbers);
} Would personally love this feature. Even blocks something like: public void Thing(double[] numbers) {
// Adding the "connecting" definition here makes it completely unambiguous what functions I'm using at the call site.
using(static A.B.C.D.E.F.Metric) {
double average = Average(numbers);
double stdDev = StandardDeviation(numbers);
}
} |
Beta Was this translation helpful? Give feedback.
-
I could imagine, that this feature can eliminate the need of disambiguation of extensions completely (i.e. we need a disambiguation syntax just for compatibility with 'legacy' extension methods). For that, aliases would not be required. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have one request I'd like to throw in related to using aliases for any type. Maybe it's a separate feature, I'm not sure. I haven't and won't have time in the immediate future to put together a super tight spec, so forgive me if I have overlooked something.
Request:
I would like to be able put using statements in any scope, not just at the top of the file. And the aliases would apply to just that scope.
Reasons:
Example:
So this:
Or this:
Would become this:
Or even better, this:
Hope this all makes sense. Thx for reading.
Beta Was this translation helpful? Give feedback.
All reactions