Feature Request: Allow Partial Classes to Extend Across Assemblies #9359
Unanswered
chris-briddock
asked this question in
Language Ideas
Replies: 2 comments
-
You can use an IL rewriter to accomplish something like this. I really don't think it belongs in the language. |
Beta Was this translation helpful? Give feedback.
0 replies
-
It will break CLR type loading massively. A type is fully determined by its assembly. Even with #9320, the allowed extension from other assembly will still be very limited. It may be involved by sub-assembly building block (dotnet/fsharp#14300), but a type can only strictly belong to one assembly. |
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
Uh oh!
There was an error while loading. Please reload this page.
-
Title: Feature Request: Allow Partial Classes to Extend Across Assemblies
Problem Statement:
Currently, partial classes in C# are limited to being defined within a single compilation unit (typically an assembly). This limitation can pose challenges in scenarios where different logical parts of a class's functionality or metadata need to be managed and potentially versioned independently across different assemblies.
For example, in large, modular applications or frameworks, it can be desirable to:
The inability to extend partial classes across assembly boundaries forces developers to use less elegant workarounds, such as:
Proposed Solution:
We propose extending the partial class concept to allow parts of a single class definition to reside in different assemblies. This would entail changes to the C# compiler and potentially the .NET runtime to enable the aggregation of partial class definitions across assembly boundaries during the compilation or loading process.
The specific mechanism for how this aggregation would work needs careful consideration, but potential approaches could involve:
Motivation/Use Cases:
The ability to extend partial classes across assemblies would offer significant benefits in various scenarios:
Considerations and Challenges:
Implementing this feature presents significant technical challenges that need to be addressed:
Alternatives Considered:
We have considered alternative approaches like using inheritance, composition, or attributes/external configuration. While these can address some of the use cases, they often lead to less intuitive code organization, require more boilerplate, or don't offer the same level of seamless integration as a language-supported partial class extension mechanism.
Conclusion:
Allowing partial classes to extend across assemblies would be a powerful language feature that could significantly improve code modularity, extensibility, and organization in complex applications. While it presents significant technical challenges, the potential benefits warrant exploration and discussion within the Roslyn community. We welcome feedback and ideas on how this feature could be designed and implemented.
Proposed Keywords for Searching: partial class, multiple assemblies, cross-assembly, modularity, extensibility, language feature, Roslyn
Beta Was this translation helpful? Give feedback.
All reactions