问题
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