C# 命名空间和程序集最佳实践

C# Namespaces and Assemblies Best Practice(C# 命名空间和程序集最佳实践)

本文介绍了C# 命名空间和程序集最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#:在将解决方案划分为命名空间和程序集时,是否有任何指导方针和最佳实践?命名空间通常应该嵌套,在顶层命名空间中包含最低级别和基本的类吗?一个程序集通常应该有一个命名空间吗?在一个命名空间中拥有多个程序集或在一个程序集中拥有多个命名空间是否存在任何缺陷.多个程序集或非常大的程序集是否有任何编译时间/运行时间处罚?

C#: are there any guidelines, best practices when it comes to dividing a solution up into namespaces and assemblies? Should namespaces normally be nested, with the most low level and fundamental classes in the top level namespace? Should there generally be one namespace to one assembly? Are there any pitfalls to having multiple assemblies in one namespace or multiple namespaces in one assembly. Are there any compile time/ run time penalties for multiple assemblies or very large assemblies?

推荐答案

C#:在将解决方案划分为命名空间和程序集时,是否有任何指导方针和最佳实践?

C#: are there any guidelines, best practices when it comes to dividing a solution up into name-spaces and assemblies?

有关命名空间的指南,请阅读框架设计指南.

For guidelines for namespaces, read the framework design guidelines.

对于程序集:根据定义,程序集是 .NET 中自描述可交付功能的最小独立版本化单元.您的软件的某些部分是否打算彼此独立地发布或版本?那么它们应该在不同的程序集中.

For assemblies: an assembly is by definition the smallest independently versionable unit of self-describing shippable functionality in .NET. Are there parts of your software that you intend to ship or version independently of each other? Then they should be in different assemblies.

命名空间通常应该嵌套,最底层和最基础的类在顶层命名空间中吗?

Should name spaces normally be nested, with the most low level and fundamental classes in the top level name space?

不一定,不.

命名空间的设计应便于用户发现和理解这些命名空间中包含的类型.也许你应该问问你的用户他们的想法.

Namespaces should be designed so that it is easy for users to discover and understand the types contained in those namespaces. Maybe you should ask your users what they think.

一个程序集通常应该有一个名称空间吗?

Should there generally be one name-space to one assembly?

不一定,不.

在一个名称空间中拥有多个程序集或在一个程序集中拥有多个名称空间是否存在缺陷?

Are their any pitfalls to having multiple assemblies in one name-space or multiple name-spaces in one assembly.

不是特别,不是.

对多个程序集或非常大的程序集是否有任何编译时间/运行时间惩罚?

Are there any compile time / run time penalties for multiple assemblies or very large assemblies?

我不知道.

这篇关于C# 命名空间和程序集最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:C# 命名空间和程序集最佳实践

基础教程推荐