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

  • Roslyn Cookbook
  • Manish Vasani
  • 171字
  • 2021-07-15 17:07:33

How to do it...

  1. In Solution Explorer, double-click on Resources.resx file in CSharpAnalyzers project to open the resource file in the resource editor.
  2. Replace the existing resource strings for AnalyzerDescription, AnalyzerMessageFormat and AnalyzerTitle with new strings.
  1. Replace the Initialize method implementation with the code from CSharpAnalyzers/CSharpAnalyzers/CSharpAnalyzers/DiagnosticAnalyzer.cs/ method named Initialize.
  2. Add private class UnusedParametersAnalyzer from CSharpAnalyzers/CSharpAnalyzers/CSharpAnalyzers/DiagnosticAnalyzer.cs/ type named UnusedParametersAnalyzer in your analyzer to perform the core method body analysis for a given method.
  3. Click on Ctrl + F5 to start a new Visual Studio instance with the analyzer enabled.

 

  1. In the new Visual Studio instance, create a new C# class library with the following code:
namespace ClassLibrary
{
public class Class1
{
void M(int param1, ref int param2, int param3, params int[] param4)
{
int local1 = param1;
param2 = 0;
}
}
}
  1. Verify the analyzer diagnostic is not reported for param1 and param2, but is reported for param3 and param4:
  1. Now, add code to use param3 in the local declaration statement, delete param4, and verify the diagnostics go away:
主站蜘蛛池模板: 乌兰察布市| 邹城市| 莱西市| 衡阳县| 静乐县| 宁远县| 富裕县| 灵石县| 锡林浩特市| 双牌县| 广南县| 亳州市| 汝城县| 奎屯市| 松原市| 日喀则市| 闸北区| 建宁县| 大渡口区| 沧源| 许昌县| 永顺县| 贵定县| 扎囊县| 德江县| 庐江县| 辉南县| 织金县| 青冈县| 庆元县| 达拉特旗| 新乐市| 沐川县| 阿拉善左旗| 英超| 永安市| 噶尔县| 大洼县| 高唐县| 夹江县| 凤山市|