[Proposal] Allow scope resolution operator on class name to define nested types #1894
Replies: 4 comments
-
This is all already possible: // in file AB_1.cs
public partial class A {
private interface IB { }
}
// in file AB_2.cs
public partial class A {
private class B : IB { }
} I don't see why you'd want to move the declaration out from the parent The |
Beta Was this translation helpful? Give feedback.
-
Also, the Regardless this sounds an awful lot like the idea to write local functions outside of the parent function and I imagine it would get rejected for the same reason, it making no sense. If you're really worried that you're one class is too long because it's hundreds of lines, but that's just because it has child classes and the main class is only 100 lines, then you're still likely following good practices it's fine. And as @HaloFour already pointed out, you can just use partial classes. |
Beta Was this translation helpful? Give feedback.
-
If there will be unnested nested classes then there should be named anonymous classes as well! |
Beta Was this translation helpful? Give feedback.
-
@dsaf And global local variables! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This proposal is to define a syntax to allow creating nested types of a class in a more friendly way so instead of:
we use the following syntax
and if we want to define the nested class
B
to be partial is it OK using the current existing syntax:the scope resolution operator here allowed moving the nested
class\interface\struct\enum
out of the main class definition under one condition that the classA
to bepartial
so when the compiler merge the proposed code we get the original definition.the new syntax will allow simplifying the nested class type definition to keep the code for large classes clean and maintainable.
Beta Was this translation helpful? Give feedback.
All reactions