组织使用指令

发布于 2024-07-10 14:17:46 字数 795 浏览 9 评论 0原文

过去几个月我一直在使用 ReSharper,除了广告之外,我无法想象自己在没有它的情况下进行编码。 因为我喜欢生活在“到底出了什么问题”的边缘,所以我决定使用最新的 ReSharper 4.5 nightly builds 碰碰运气。 一切都很好。

但是,我注意到 using 指令分组格式已经改变,我想知道哪个更接近通用标准:

[旧]

#region Using directives
using System.X;
using System.Y;
using System.Z;
using System.A;
#region
namespace X { ... }

[新]

namespace X {
#region Using directives
using System.X;
using System.Y;
using System.Z;
using System.A;
#region
...
}

除了延迟加载引用之外,它还有什么特殊用途吗? (一直在阅读 Scott Hanselman 对此的看法@ http://www.hanselman.com/blog/BackToBasicsDoNamespaceUsingDirectivesAffectAssemblyLoading。 aspx

谢谢;

I've been using ReSharper for the past months and, advertising aside, I can't see myself coding without it. Since I love living on the bleeding "What the hell just went wrong" edge, I decided to try my luck w/ the latest ReSharper 4.5 nightly builds. It's all nice.

However, I've noticed that the using directives grouping format has changed, and I wanted to know which is closer to the general standards:

[OLD]

#region Using directives
using System.X;
using System.Y;
using System.Z;
using System.A;
#region
namespace X { ... }

[NEW]

namespace X {
#region Using directives
using System.X;
using System.Y;
using System.Z;
using System.A;
#region
...
}

Other than just lazy loading references, does it serve any special purpose? (Been reading Scott Hanselman's take on this @ http://www.hanselman.com/blog/BackToBasicsDoNamespaceUsingDirectivesAffectAssemblyLoading.aspx)

Thanks;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绿光 2024-07-17 14:17:46

正如 Scott 在他的文章中继续发现的那样,这两种情况之间没有运行时差异。 因此,它不能达到延迟加载引用的目的。

如果你从头到尾阅读 Scott 博客中的评论,你还会看到将这个传闻传递给 Scott(Mike Brown)的开发者说他只是听说过这个,并没有亲自测试过。

也就是说,如果您为命名空间内的类型设置别名,并且您有另一个类型,那么您放置 using 指令的位置可能会产生不同,因为会出现编译器错误与命名空间中定义的名称相同。 但这当然没有运行时差异。

最后,我相信 MS 编码指南要求按照 ReSharper 4.5 的方式进行操作。 但“因为微软是这么说的”而盲目遵循这条规则是愚蠢的,因为

  1. 它已被证明没有任何好处。
  2. 您的团队(或您的)通常的编码风格可能非常不同。

As Scott proceeds to discover in his post, there is no runtime difference between these two cases. Therefore, it does not serve the purpose of lazy loading references.

If you read the comments in Scott's blog all the way to the end, you will also see that the developer who passed this rumor to Scott (Mike Brown) says that he had only heard of this and not tested it himself.

That said, it is possible that where you put the using directives might make a difference by giving a compiler error if you set up an alias for a type inside a namespace, and you have another type with the same name defined in the namespace. But that's no runtime difference of course.

Finally, I believe that MS coding guidelines say to do it as ReSharper 4.5 does. But it's silly to blindly follow this rule "because MS says so", since

  1. It has been proved that it offers no benefit.
  2. Your team's (or your) usual coding style may very well be different.
清秋悲枫 2024-07-17 14:17:46

嗯,通常是主观的。 :) 但对我来说,通常是“旧”方式。

Well, the usual is subjective. :) But for me, the usual is the "old" way.

残花月 2024-07-17 14:17:46

哦,我的错。 我搜索的时候没有看到这个问题。 我知道这样做很愚蠢,因为 MS 是这么说的,但总的来说,“通常”的方法是什么?

据了解,我经常使用 ReSharper 的代码清理功能,所以说实话,我只是想知道。

Oh, my bad. I didn't see that question when I searched for it. I know it's silly to do it 'cause MS says so, but in general, what's the "usual" approach to this?

I'm known to use ReSharper's code cleanup a lot, so I'm just wondering, to be honest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文