我如何禁用产生code特定的FxCop规则? [英] How do I disable a specific FxCop rule in generated code?
问题描述
我有地方,我需要禁用某些规则(在这种情况下,CA1819:PropertiesShouldNotReturnArrays)一个问题产生的code。如果是我自己的code,我本来只是增加了一个燮pressMessage
属性给定的功能,仅此而已。很显然,我不能这样做,在产生code,因为它会在下一版本会丢失。
自动生成的code:
[系统。codeDom.Compiler.Generated codeAttribute(XSD,4.0.30319.1)
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(code)
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = TRUE)]
[System.Xml.Serialization.XmlRootAttribute(命名空间=,ISNULLABLE = FALSE)]
公共部分类ListViewTable {
私人ListViewTableRow [] itemsField;
///<备注/>
[System.Xml.Serialization.XmlElementAttribute(行,表= System.Xml.Schema.XmlSchemaForm.Unqualified)
公共ListViewTableRow []项目{
得到 {
返回this.itemsField;
}
组 {
this.itemsField =价值;
}
}
}
在产品
属性生成
<消息类型名=PropertiesShouldNotReturnArrays范畴=Microsoft.PerformanceCheckId =CA1819状态=活动创建=2013年10月29日14:47:04Z FixCategory =破>
<发行确定性=50级=警告路径=D:\项目\ FlightPlanning的\ src \核心\ FpesCustomControls文件=AoiSchema.cs行=32>到改变ListViewTable.Items返回集合或使其方法和LT; /发行>
< /消息>
要解决这个问题,模块级燮pressions都可以使用。在项目的任何其他来源的文件,可以用下面的语句(必须使用指令之后):
[模块:燮pressMessage(Microsoft.Performance,CA1819:PropertiesShouldNotReturnArrays,理由=生成的code,
范围=成员,目标=FlightPlanning.AoiSchema.ListViewTable。#项目)
困难的是找到正确的名称为目标,因为它必须是一个确切的完全合格的字符串。幸运的是,FxCop的GUI提供帮助,以得到正确的消息:只需右键单击该错误,选择复制 - 作为,然后选择模块级燮pression
I had a problem where I needed to disable a certain rule (in this case CA1819:PropertiesShouldNotReturnArrays) for generated code. If it was my own code, I would have just added a SuppressMessage
Attribute to the given function and that's it. Obviously, I can't do that in generated code because it will be lost on the next build.
Automatically generated code:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class ListViewTable {
private ListViewTableRow[] itemsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Row", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ListViewTableRow[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}
The Items
property generates
<Message TypeName="PropertiesShouldNotReturnArrays" Category="Microsoft.Performance" CheckId="CA1819" Status="Active" Created="2013-10-29 14:47:04Z" FixCategory="Breaking">
<Issue Certainty="50" Level="Warning" Path="D:\Projects\FlightPlanning\src\Core\FpesCustomControls" File="AoiSchema.cs" Line="32">Change 'ListViewTable.Items' to return a collection or make it a method.</Issue>
</Message>
To solve the problem, module-level suppressions can be used. In any other source file of the project, the following statement can be used (must be right after the using directives):
[module: SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Generated code",
Scope = "member", Target = "FlightPlanning.AoiSchema.ListViewTable.#Items")]
The difficulty is finding the right name for the Target, because it must be an exact fully qualified string. Luckily, the FxCop gui offers help to generate the correct message: Just right-click the error, select "Copy-As" and choose "Module level Suppression"
这篇关于我如何禁用产生code特定的FxCop规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!