Hiding namespaces containing only internal types in a class library?

后端 未结 2 1437
别那么骄傲
别那么骄傲 2020-12-30 19:01

I have a class library that has a couple of namespaces containing only internal types.

However, when using the class library in an application project, the namespace

相关标签:
2条回答
  • 2020-12-30 19:04

    I've come up against this before and found no solution, only a workaround which may or may not work in your project. Instead of defining a namespace you could use an nested static class?

    0 讨论(0)
  • 2020-12-30 19:29

    It depends on how you're referencing your class library:

    • If you have the class library project contained within your solution and use a project reference, you'll always see that empty namespace via Intellisense.
    • If you're referencing a compiled dll of your class library, you won't see the namespace popping up in intellisense, provided it contains only internal members.

    Try this:

    namespace ClassLibrary1
    {
        namespace Internal
        {
            internal class InternalClass
            {
                public int internalStuff { get; set; }
            }
        }
    
        namespace Public
        {
            public class PublicClass
            {
                public int publicStuff { get; set; }
            }
        }
    }
    

    If you reference this via a project reference, you'll see the empty namespace. If you reference a dll of it, you won't.

    0 讨论(0)
提交回复
热议问题