Replies: 1 comment
-
I was about to raise a similar issue:
You might not want to pull in global functions into the entire file. I thought this was a good feature suggestion because it appears to not cause a lot of work compared to the benefit. I now see that this was raised before in a similar way: Proposal: |
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
-
@TyreeJackson commented on Tue Aug 11 2015
Problem
When using nested classes, especially combined with generic type parameters, resolving nested types outside of their nesting hierarchies and from within another set of nested class hierarchies become clunky and difficult to read.
Consider the following example classes. (Note, that in the real world version of this example, the nested classes would be in separate files and partial class signatures would be used to span the nesting classes across the files. The main class file for any class would solely contain the full class signature.)
Now consider the following unit test classes. (Note, that again in the real world that these classes would be separated into multiple files using partial class declarations.)
Notice how clunky and unwieldy the source class type names are getting in the test classes at their corresponding levels in the hierarchy.
Proposal
Add support for the
using
statement within the scope of a class in a specific file.It would be great if we could write the following for the test classes in place of the above:
Class level
using
statements would greatly help in cases where generic type parameters are being shared across multiple nested classes in multiple levels of class nesting.I apologize for the obfuscation of the type names in the example above.
@dsaf commented on Tue Aug 11 2015
Looks like a very narrow use case on the surface.
Not sure if naming is the biggest problem with readability here. It is very tempting to provide critique of the example code instead of the suggested language feature:
@TyreeJackson commented on Tue Aug 11 2015
@dsaf
Please critique away. I'm always up for learning a new way to solve a problem.
If you are concerned with the use of partial classes and sharing of generic type parameters across nested classes, I will state that I've tried numerous approaches to enforce type safety across these 'layers' for years. In order to reduce redundant type parameter declarations and type casting, the best solution I came up with was to share type parameters across multiple types by nesting them within an outer class that declares the type parameters. In fact, I just submitted a different "issue" on here to discuss that very concept and the idea of introducing generic/parametric modules or namespaces. Check it out on #4494. The same code from this issue is used there to demonstrate the problem of breaking out the classes directly into classical namespaces.
@svick commented on Sat Apr 02 2016
Note that this is not about the
using
statement, it's about theusing
directive. @TyreeJackson could you change the title of the issue?Beta Was this translation helpful? Give feedback.
All reactions