为什么 StyleCop 规则不允许在代码中使用 #region?
我收到如下屏幕截图所示的警告,我不明白为什么会这样对待。我经常需要“区域化”我的代码。
你怎么认为?
I get the warning as below screenshot and I don't understand why it would be treated like that. I often need to "regionize" my codes.
What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然这个 StyleCop 规则确实只是一个建议,但我不会禁用它。这些#region 块通常用作视觉和阅读辅助工具。这通常表明某个函数或子程序太长和/或由多个部分组成。您可以使用它作为重构非常长的代码的指南或触发器。
While it is true that this StyleCop rule is just a recommendation, I would not disable it though. More often than not, these #region blocks are used as a visual and reading aid. It is usually a sign that a certain function or subroutine is too long and/or composed of multiple parts. You can use this as a guide or trigger to refactor that very long code.
默认的 StyleCop 规则并不是一成不变的。
我不记得这个链接了,但 StyleCop 团队的某人曾经说过默认规则只是建议。
因此,如果您不喜欢它,请随意禁用规则 SA1123。
The default StyleCop rules are not set in stone.
I don't remember the link anymore, but someone from the StyleCop team once said that the default rules are just suggestions.
So feel free to disable rule SA1123 if you don't like it.