![](/img/trans.png)
[英]how do i code a RemoveCallsToGCKeepAlive exception to be picked up in FxCop?
[英]How do I disable a specific FxCop rule in generated code?
我遇到了需要為生成的代碼禁用特定規則(在這種情況下為CA1819:PropertiesShouldNotReturnArrays)的問題。 如果這是我自己的代碼,則只需將SuppressMessage
屬性添加到給定的函數即可。 顯然,我無法在生成的代碼中執行此操作,因為它將在下一個版本中丟失。
自動生成的代碼:
[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;
}
}
}
Items
屬性生成
<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>
為了解決該問題,可以使用模塊級抑制。 在項目的任何其他源文件中,都可以使用以下語句(必須在using指令之后):
[module: SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Generated code",
Scope = "member", Target = "FlightPlanning.AoiSchema.ListViewTable.#Items")]
困難在於為目標找到正確的名稱,因為它必須是確切的完全限定的字符串。 幸運的是,FxCop gui提供了幫助以生成正確的消息:只需右鍵單擊錯誤,選擇“復制為”,然后選擇“模塊級別抑制”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.