Created
May 1, 2015 05:15
-
-
Save JoshVarty/ff4ba612e984c5c29e19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DiagnosticAnalyzer(LanguageNames.CSharp)] | |
public class Analyzer1Analyzer : DiagnosticAnalyzer | |
{ | |
... | |
public override void Initialize(AnalysisContext context) | |
{ | |
// TODO: Consider registering other actions that act on syntax instead of or in addition to symbols | |
context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.NamedType); | |
} | |
private static void AnalyzeSymbol(SymbolAnalysisContext context) | |
{ | |
// TODO: Replace the following code with your own analysis, generating Diagnostic objects for any issues you find | |
var namedTypeSymbol = (INamedTypeSymbol)context.Symbol; | |
// Find just those named type symbols with names containing lowercase letters. | |
if (namedTypeSymbol.Name.ToCharArray().Any(char.IsLower)) | |
{ | |
// For all such symbols, produce a diagnostic. | |
var diagnostic = Diagnostic.Create(Rule, namedTypeSymbol.Locations[0], namedTypeSymbol.Name); | |
context.ReportDiagnostic(diagnostic); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment