in src/Analyzers/ExpressionDefinition.Analyzer.cs [53:84]
private static void AnalyzeMethod(SyntaxNodeAnalysisContext context)
{
if (context.Node is not MethodDeclarationSyntax method)
{
throw new Exception();
}
var model = context.SemanticModel;
var isExpression = method.AttributeLists.ContainsExpressionAttribute(model);
if (!isExpression) return;
var type = model.GetTypeInfo(method.ReturnType).Type;
if (type == null)
{
var diagnostic = Diagnostic.Create(Rules.Expression.ReturnTypeNotAllowed, method.ReturnType.GetLocation(),
method.ReturnType.ToString());
context.ReportDiagnostic(diagnostic);
}
else
{
var fullTypeName = type.ToFullyQualifiedString();
if (!AllowedExpressionReturnTypes.Contains(fullTypeName))
{
var diagnostic = Diagnostic.Create(Rules.Expression.ReturnTypeNotAllowed,
method.ReturnType.GetLocation(), fullTypeName);
context.ReportDiagnostic(diagnostic);
}
}
CheckParameters(context, method.ParameterList);
}