- Roslyn Cookbook
- Manish Vasani
- 227字
- 2021-07-15 17:07:39
How to do it...
- 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.
- 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:

- 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:

- 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
{
}
}
- Right-click on the rule node, click on Set Rule Set Severity, and change the severity from Default to Warning:

- Confirm that CA1813 is now reported for the preceding code:

- Save the current project and then close and re-open the solution.
- 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.
推薦閱讀
- Implementing Modern DevOps
- 從零開始:數(shù)字圖像處理的編程基礎(chǔ)與應(yīng)用
- OpenDaylight Cookbook
- Python數(shù)據(jù)可視化:基于Bokeh的可視化繪圖
- Vue.js快速入門與深入實(shí)戰(zhàn)
- C語言程序設(shè)計(jì)案例式教程
- CKA/CKAD應(yīng)試教程:從Docker到Kubernetes完全攻略
- PhpStorm Cookbook
- Learning Python Design Patterns
- Learning FuelPHP for Effective PHP Development
- UML 基礎(chǔ)與 Rose 建模案例(第3版)
- INSTANT Sinatra Starter
- 用案例學(xué)Java Web整合開發(fā)
- Mastering C++ Multithreading
- Android開發(fā)權(quán)威指南(第二版)