官术网_书友最值得收藏!

How to do it...

  1. Open a C# project, say ClassLibrary, with the analyzer NuGet package System.Runtime.Analyzers.nupkg pre-release version 1.2.0-beta2 installed in it.
  2. In the solution explorer, expand References | Analyzers nodes to view the analyzer assemblies installed through the analyzer NuGet package(s). We should see two analyzer assemblies, System.Runtime.Analyzers and System.Runtime.CSharp.Analyzers:
  1. Expand the System.Runtime.Analyzers node to view all the CAXXXX rules implemented in the assembly and click on a specific rule, say CA1813: Avoid unsealed attributes, to view the rule properties, such as ID, Message, Title, Description, Category, Effective severity, Enabled by default, and so on, in the Properties Window:
  1. Note that the CA1813 rule's Enabled by default is False, which means that the rule is turned off by default. We can confirm this by adding the following source code that violates this rule because we declared a public unsealed attribute, but CA1813 is not reported for the violation:
using System;

namespace ClassLibrary
{
[AttributeUsage(AttributeTargets.All)]
public class MyAttribute: Attribute
{
}
}
  1. Right-click on the rule node, click on Set Rule Set Severity, and change the severity from Default to Warning:
  1. Confirm that CA1813 is now reported for the preceding code:
  1. Save the current project and then close and re-open the solution.
  2. Verify that the warning CA1813 still shows up for the preceding source code, confirming that the rule set severity change was persisted for the project.
主站蜘蛛池模板: 襄汾县| 工布江达县| 万宁市| 鱼台县| 诏安县| 永顺县| 湘乡市| 武安市| 湄潭县| 延吉市| 大姚县| 云霄县| 南川市| 香港 | 荔浦县| 独山县| 平阴县| 什邡市| 舒城县| 当雄县| 沽源县| 武穴市| 宁津县| 三穗县| 铁岭市| 湘乡市| 观塘区| 永嘉县| 广安市| 遂溪县| 保定市| 克山县| 始兴县| 大港区| 宁国市| 文安县| 哈巴河县| 嘉兴市| 喜德县| 常州市| 淮阳县|