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

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.

 

  1. Add a private class CompilationAnalyzer from CSharpAnalyzers/CSharpAnalyzers/CSharpAnalyzers/DiagnosticAnalyzer.cs/ type named CompilationAnalyzer in your analyzer to perform the core method body analysis for a given method.
  2. Click on Ctrl + F5 to start a new Visual Studio instance with the analyzer enabled.
  3. In the new Visual Studio instance, enable full solution analysis for C# projects by following the steps here: https://msdn.microsoft.com/en-us/library/mt709421.aspx
  1. In the new Visual Studio instance, create a new C# class library with the following code:
namespace MyNamespace
{
public class InsecureMethodAttribute : System.Attribute { }

public interface ISecureType { }

public interface IInsecureInterface
{
[InsecureMethodAttribute]
void F();
}

class MyInterfaceImpl1 : IInsecureInterface
{
public void F() {}
}

class MyInterfaceImpl2 : IInsecureInterface, ISecureType
{
public void F() {}
}

class MyInterfaceImpl3 : ISecureType
{
public void F() {}
}
}
  1. Verify the analyzer diagnostic is not reported for MyInterfaceImpl1 and MyInterfaceImpl3, but is reported for MyInterfaceImpl2:
  1. Now, change MyInterfaceImpl2 so that it no longer implements IInsecureInterface and verify that the diagnostic is no longer reported.
class MyInterfaceImpl2 : ISecureType
{
public void F() {}
}
主站蜘蛛池模板: 调兵山市| 许昌市| 克拉玛依市| 资溪县| 黑山县| 深圳市| 佳木斯市| 子长县| 广德县| 丹凤县| 昆山市| 揭西县| 尼勒克县| 莲花县| 吉木乃县| 缙云县| 麻城市| 遂平县| 富平县| 西城区| 建宁县| 洛川县| 威信县| 高尔夫| 汉中市| 梁河县| 泸定县| 南涧| 六枝特区| 台江县| 华容县| 霸州市| 银川市| 宜城市| 云霄县| 辉县市| 桂林市| 环江| 西峡县| 司法| 屏南县|