Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment