Roslyn Analyzer which compares against separate class file

↘锁芯ラ 提交于 2019-12-08 05:22:28

问题


I'm writing a Roslyn analyzer which compares checks if const are already declared in a 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);
}

I'm confused on how to grab out the designer.cs from the resx file.

private static void AnalyzeConstForLocalization(SyntaxNodeAnalysisContext context)
{
}

How can I get the Designer.cs from the SyntaxNodeAnalysisContext. If I'm using the wrong RegisterSyntaxNodeAction, what action should I use in which I can analzye consts an resx file and how can I find the file.

来源:https://stackoverflow.com/questions/44075087/roslyn-analyzer-which-compares-against-separate-class-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!