[DiagnosticAnalyzer(LanguageNames.CSharp)] public class MyAnalyzer : DiagnosticAnalyzer { public override ImmutableArrayIn the above example, we create a custom analyzer that flags usage of obsolete methods in the code and generates a warning diagnostic message. We register this analyzer with the `AnalysisContext` provided by the package library and analyze each `InvocationExpression` syntax node to see if it is marked as obsolete. If it is, we create a diagnostic message using the `Diagnostic.Create` method and report it using the `context.ReportDiagnostic` method. Package library: `Microsoft.CodeAnalysis.Diagnostics`SupportedDiagnostics => ImmutableArray.Create(MyRule); public static readonly DiagnosticDescriptor MyRule = new DiagnosticDescriptor( "MA0001", "My Analyzer", "Avoid using obsolete methods", "Usage", DiagnosticSeverity.Warning, true); public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InvocationExpression); } private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { var invocation = (InvocationExpressionSyntax)context.Node; var symbolInfo = context.SemanticModel.GetSymbolInfo(invocation); var symbol = symbolInfo.Symbol; if (symbol?.IsObsolete() == true) { var diagnostic = Diagnostic.Create(MyRule, invocation.GetLocation(), symbol.Name); context.ReportDiagnostic(diagnostic); } } }