问题描述
我发现通常有一个单一类型或命名空间,它将任何特定的枚举作为一个参数,因此我一直定义那些枚举。最近,我有一个同事对于这是一个愚蠢的事情做了大量的事情,你应该永远有一个枚举命名空间在项目的根目录,您定义了所有的枚举类型。找到枚举类型的最佳位置在哪里?
到其他类型?将它们保留在相同的命名空间中,因为它们可能被使用 - 假设它们将被其他类使用,在自己的文件中使它们成为顶级类型。
我唯一一种类型的类型通常是聚集在一起的是代理 - 我有时候有一个Delegates.cs文件与一堆代理。更少的.NET 3.5和Func / Action ,记住你。
I have found that there is generally a singe type or namespace that takes in any particular enum as a parameter and as a result I have always defined those enums there. Recently though, I had a co-worker make a big deal about how that was a stupid thing to do, and you should always have an enum namespace at the root of your project where you define everyone of your enum types.
Where is the best place to locate enum types?
Why treat enums differently to other types? Keep them in the same namespace as they're likely to be used - and assuming they're going to be used by other classes, make them top-level types in their own files.
The only type of type which I do commonly clump together is delegates - I sometimes have a Delegates.cs file with a bunch of delegates in. Less so with .NET 3.5 and Func/Action, mind you.
这篇关于枚举类型的最佳位置在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!