5

特定のプロパティに対して次のStyleCopメッセージを抑制しようとしています。

SA1513: Statements or elements wrapped in curly brackets must be followed by a blank line.

私は次のことをしようとしていますが、うまくいかないようです:

    [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")]
    public string CustomerId
    {
        get
        {
            return this.GetProperty(CustomerIdProperty);
        }
        set
        {
            if (this.IsNew)
            {
                this.SetProperty(CustomerIdProperty, value);
            }
            else
            {
                throw new ReadOnlyException("Id value can only be changed for a new record.");
            }
        }
    }

私は何か間違ったことをしているだけですか?それともこれは不可能ですか?これは良いルールですが、私の場合はプロパティには有効ではありません。

アップデート

DocumentationRulesからLayoutRulesに切り替えようとしました...それでも抑制されません。

    [DataObjectField(true, false)]
    [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")]
    public string CustomerId
    {
        get
        {
            return this.GetProperty(CustomerIdProperty);
        }
        set
        {
            if (this.IsNew)
            {
                this.SetProperty(CustomerIdProperty, value);
            }
            else
            {
                throw new ReadOnlyException("Id value can only be changed for a new record.");
            }
        }
    }
4

6 に答える 6

3

これはStyleCopの問題かもしれないと思います。どのバージョンをインストールしていますか? このページには次のように記載されています。

StyleCop 4.3.2 以降では、ソース コード内に抑制属性を追加することで、ルール違反の報告を抑制することができます。

メッセージを抑制できないことがわかりました。私が使用したインストーラーは、バージョンを 4.3 として提供します。Codeplexの最新バージョンは4.4.0.0です。そのバージョンがインストールされていることを確認してください。

アップデート

私はいくつかのチェックを行ってきましたが、DocumentationRules を抑制することができます:

    [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules",
                     "SA1600:ElementsMustBeDocumented",
                     Justification = "Reviewed. Suppression is OK here.")]

SpacingRules や LayoutRules ではありません。ただし、これが当てはまる理由を示すものは何も見つかりませんでした。

于 2010-04-10T16:09:30.457 に答える
3
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")]

最新の StyleCop で動作します。「マイクロソフト」を削除しました。プレフィックス。

于 2015-04-28T10:15:11.310 に答える
3

あなたの抑制は を使用しMicrosoft.StyleCop.CSharp.DocumentationRulesます。あるべきだと思いますMicrosoft.StyleCop.CSharp.LayoutRules

于 2010-04-10T15:49:24.427 に答える
2

ルールを抑制する方法を理解するために、StyleCopのドキュメントを注意深く読んでください。以下は私のコードで機能しました:

    [SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules",
    "SA1402:FileMayOnlyContainASingleClass",
    Justification = "Splitting this file into classes would get too confusing.")]

ヘルプファイルから:

SuppressMessage属性の形式は次のとおりです。

[SuppressMessage( "ルールカテゴリ、"ルールID "、"正当化 ")]

どこ:

  • ルールカテゴリ-ルールが定義されているStyleCopルール名前空間。たとえば、Microsoft.StyleCop.CSharp.DocumentationRules

  • ルールID -shortname:longnameの形式を使用したルールの識別子。

    たとえば、SA1600:ElementsMustBeDocumented

  • 正当化-メッセージを抑制する理由を文書化するために使用されるテキスト。

また、すでに述べたように、正しいルールの名前空間を参照していることを確認してください。

于 2011-02-18T01:17:02.050 に答える
2

StyleCop には、特定の種類のルールのみを抑制できるというバグがあります。これは、まもなくリリースされる予定の StyleCop 4.4 で修正される予定です。

于 2010-04-11T01:34:30.803 に答える
-2

get ブロックと set ブロックの間に空白行を入れるだけです。
空白行を 1 行追加するだけで問題は解決します。

于 2010-08-06T16:45:57.310 に答える