简体   繁体   English

当我在VS2010中使用WinForms(C#)设计器时,它仍会生成StyleCop抱怨的代码

[英]When I use WinForms (C#) designer in VS2010, it still generates code that StyleCop complains about

Some problems that I recall (there may be more): 我记得的一些问题(可能还有更多):

  1. Includes regions 包括地区
  2. Does not use this. 不使用this. prefix for member variables and methods 成员变量和方法的前缀
  3. Includes comments like the one below ( having // by itself catches the eye of StyleCop) 包括下面的评论( //本身就能吸引StyleCop的眼球)

     // // fileNameTextBox // 

If I make a change to the text, and then open the designer again, and screws up my previously perfected fruits of hard labor. 如果我对文本进行了更改,然后再次打开设计师,并搞砸了我以前完善的苦工结果。 How did / would you solve this problem? 你是怎么解决这个问题的?

I heard but did not personally experience a similar problem with WPF. 我听说但是没有亲自遇到类似WPF的问题。 How did / would you fix that? 怎么/你会解决这个问题?

Thanks. 谢谢。

There are several ways to make StyleCop ignore generated code: 有几种方法可以让StyleCop忽略生成的代码:
StyleCop: How To Ignore Generated Code StyleCop:如何忽略生成的代码

As I recall it, ignoring generated code is the default setting (at least, it ignores my VS 2008 generated code with the standard settings). 我记得,忽略生成的代码是默认设置(至少,它忽略了我的 VS 2008生成的代码与标准设置)。

I don't use VS 2010, so I don't know if they changed the designer generated files somehow so that StyleCop doesn't recognize them as generated anymore. 我不使用VS 2010,所以我不知道他们是否以某种方式改变了设计器生成的文件,因此StyleCop不再将它们识别为已生成。
Maybe the link helps you to figure that out in your code. 也许该链接可以帮助您在代码中找到答案。

StyleCop can be instructed to ignore generated source files. 可以指示StyleCop忽略生成的源文件。 I don't know why designer-generated files have to adhere to any arbitrary coding standard – the only thing that should ever read or write them is an automated tool, not the developer. 我不知道为什么设计器生成的文件必须遵守任何编码标准 - 唯一应该读取或写入它们的是自动化工具,而不是开发人员。

Code styles are mainly there to help developers. 代码样式主要是帮助开发人员。 Code generators certainly couldn't care less. 代码生成器肯定不在乎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在VS2010中是否有一种快速方法强制所有winforms designer.cs自动生成的代码在ac#项目中重新生成? - Is there a quick way in VS2010 to force all winforms designer.cs autogenerated code to regenerate themselves in a c# project? 在VS2010 c#中从Designer更改窗体不会在我运行它时更改窗体 - Changing form in VS2010 c# From Designer doesn't change the form when i run it VS2010 C#WinForms可插入控件 - VS2010 C# WinForms Pinnable Control 如何使用StyleCop或VS2010检测重新抛出C#异常的坏方法? - How to detect a bad way of re-throwing a C# Exception using StyleCop or VS2010? 如何在已完成并放入GAC中的VS2010中的C#项目中修改代码 - How can I amend code in a C# project in VS2010 that I have finalised and placed in the GAC VS2010扩展,用于格式化C#代码 - VS2010 extension for formatting C# code 使用xsd.exe(VS2010)从xsd生成C#代码时发生StackOverFlowException - StackOverFlowException when generating C# code from xsd using xsd.exe (VS2010) 为什么在VS2010 C#中不能使用ManagementObjectSearcher - Why can't use ManagementObjectSearcher in VS2010 C# 是否可以使用VS2010的C#5编译器? - Is it possible to use the C# 5 compiler from VS2010? 如何在VS2010 Professional中为C#项目自定义代码分析词典? - How do I customize the Code Analysis Dictionary for a C# project in VS2010 Professional?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM