public override void VisitClassDeclaration(ClassDeclarationSyntax node) { IImmutableList <ITypeSymbol> baseTypes = SemanticModel.GetAllBaseTypeSymbols(node); bool isController = baseTypes.Any(t => t.Equals(KnownTypes.Controller)); if (!isController) { return; } IImmutableList <AttributeUsageInfo> attributeInfo = SemanticModel.GetAttributeInfo(node.AttributeLists); bool isVersioned = attributeInfo.Any(info => info.AttributeType.Equals(KnownTypes.ApiVersionAttribute)); if (!isVersioned) { return; } base.VisitClassDeclaration(node); }
private IEnumerable <(ITypeSymbol symbol, TypeSyntax syntax)> GetContractTypes( MethodDeclarationSyntax method) { yield return(SemanticModel.GetTypeSymbol(method.ReturnType), method.ReturnType); foreach ((ITypeSymbol type, IImmutableList <AttributeParameterInfo> parameters) in SemanticModel .GetAttributeInfo(method.AttributeLists)) { if (!SemanticModel.IsAssignableTo(type, KnownTypes.ProducesResponseTypeAttribute)) { continue; } List <(ExpressionSyntax expression, ITypeSymbol type)> typeParameters = parameters.Select( p => (expression: p.Expression, type: SemanticModel.GetTypeSymbol(p.Expression))) .Where(p => p.type.Equals(KnownTypes.Type)) .ToList(); if (typeParameters.Count == 0) { continue; } (ExpressionSyntax expression, ITypeSymbol type)typeParameter = typeParameters[0]; var visitor = new GetTypeOfExpressionSymbolVisitor(); visitor.Visit(typeParameter.expression); yield return(SemanticModel.GetTypeSymbol(visitor.Type), visitor.Type); } foreach (ParameterSyntax parameter in method.ParameterList.Parameters) { yield return(SemanticModel.GetTypeSymbol(parameter.Type), parameter.Type); } }