IMethodSymbol methodSymbol = ...; if(methodSymbol.Locations.First().GetLineSpan().EndLinePosition.Line > 80) { Diagnostic.Create( new DiagnosticDescriptor("error001", "Method too long", "The method length exceeds 80 lines", "Usage", DiagnosticSeverity.Warning, true), methodSymbol.Locations.First()); }
IMethodSymbol methodSymbol = ...; if(!methodSymbol.GetAttributes().Any(attr => attr.AttributeClass.Name == "Route")) { Diagnostic.Create( new DiagnosticDescriptor("error002", "Route attribute not found", "The method must have a Route attribute", "Usage", DiagnosticSeverity.Error, true), methodSymbol.Locations.First()); }This example uses CreateDiagnostic to create an error diagnostic message with the descriptor and message in the first argument, if the specified method does not have the Route attribute. The location of the method symbol is used as the second argument. Package Library: The IMethodSymbol interface is part of the Roslyn .NET Compiler Platform. The package library would therefore be Microsoft.CodeAnalysis.CSharp.