Roslyn Analyzer与单独的类文件进行比较

时间:2017-05-19 16:42:05

标签: c# roslyn

我正在写一个Roslyn分析器,它比较检查const是否已在Localization Resx中声明。

public const string DiagnosticId = "LocalizationTool";

// You can change these strings in the Resources.resx file. If you do not want your analyzer to be localize-able, you can use regular strings for Title and MessageFormat.
// See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/Localizing%20Analyzers.md for more on localization
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(Resources.AnalyzerTitle), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(Resources.AnalyzerMessageFormat), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(Resources.AnalyzerDescription), Resources.ResourceManager, typeof(Resources));
private const string Category = "Naming";

private static DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Rule); } }

public override void Initialize(AnalysisContext context)
{
   context.RegisterSyntaxNodeAction(AnalyzeConstForLocalization, SyntaxKind.FieldDeclaration);
}

我对如何从resx文件中获取designer.cs感到困惑。

private static void AnalyzeConstForLocalization(SyntaxNodeAnalysisContext context)
{
}

如何从SyntaxNodeAnalysisContext获取Designer.cs。如果我使用了错误的RegisterSyntaxNodeAction,我应该使用哪种操作,我可以使用analzye来获取resx文件,如何找到该文件。

0 个答案:

没有答案