Separate projects or multiple class files … namespace best practice in C#

后端 未结 5 1064
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 03:32

I\'m creating a library for use with an application that I am building. I am building a name space structure similar to below.

MyNamespace.Validation
MyName         


        
5条回答
  •  广开言路
    2021-01-13 04:09

    I would say it depends.

    • First, it's best practice to put each class in its own file.
    • If you go with one project, I would create folders for each namespace inside that project, and put the code files in the appropriate folder.
    • Doing the above, Visual Studio will automatically create new class files within the correct namespace

    I think the real question here is this though:

    If this is only ever going to be used once, putting everything in one project would make sense. However, if this code is going to be reusable, you should think if you would ever reuse just a part (or one sub-namespace) of this library. If the answer is yes, I would break apart the namespaces into separate projects, so in the future, you could only include the projects you needed.

提交回复
热议问题