Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Is it possible to re-export types similar to JS?
I'm writing a library "MyLibrary".
In there, I group code into sections that make sense.
Let's say I have a folder "Reports" and a folder "Helpers".
I would like to have my code separated while working on it, but would like my users to just import "MyLibrary" and have all the important stuff together there.
In JS, I would be able to roughly do this:
import ReportFactory from './Reports/ReportFactory';
import StringHelper from './Helpers/StringHelper';
export {ReportFactory, StringHelper}
Is something like this possible in C#?
I know I could keep the files under that path, while letting them have a different namespace, but that's very hacky and I'd rather not, then.
So far I have stumbled on type forwarding, but that redirects to another assembly while keeping the namespace the same.
Is there a way to make such a "summary" namespace for the users of my library?
1 answer
I have not found a way of doing what I asked for in the question.
However, from looking at Microsoft.Extensions.[...]
packages, it seems .NET follows a different approach:
- For ease of development, things are put into different projects/NuGet packages
- For ease of consumption, things are put under the same namespace, even though they might be in different project.
For example, IConfigurationBuilder
from the NuGet package Microsoft.Extensions.Configuration.Abstractions
is available in the namespace Microsoft.Extensions.Configuration
.
1 comment thread