private bool IsReturnMatch(MethodTemplate template, string returnType) { MethodTemplateMatchCondition condition = template.MatchCondition; return(condition.ReturnTypeRule switch { ReturnTypeRule.Any => true, ReturnTypeRule.Specified => condition.ReturnType == returnType, _ => throw new NotImplementedException(condition.ReturnTypeRule.ToString()) });
private static void PopulateReturnTypeMatchConditions( MethodTemplateMatchCondition matchOnCondition, SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration) { if (methodDeclaration.ReturnType is QualifiedNameSyntax { Left : QualifiedNameSyntax { Left : QualifiedNameSyntax { Left : IdentifierNameSyntax { Identifier : { Text : "Decorated" } },
private static MethodTemplate ParseMethod(SemanticModel semanticModel, MethodDeclarationSyntax methodDeclaration) { var matchCondition = new MethodTemplateMatchCondition(); PopulateReturnTypeMatchConditions(matchCondition, semanticModel, methodDeclaration); PopulateParameterTypeMatchConditions(matchCondition, semanticModel, methodDeclaration); string body = methodDeclaration.ExpressionBody?.Expression != null ? $"return {methodDeclaration.ExpressionBody.Expression}" : methodDeclaration.Body.ToString(); return(new MethodTemplate { Name = methodDeclaration.Identifier.Text, Async = methodDeclaration.IsAsync(), MatchCondition = matchCondition, Body = body }); }