public ReturnSyntaxNodeHandlerContext(SemanticModel model, ParseContext context, IMethodSymbol method, ReturnSyntaxNodeHandlerFactory factory) { Model = model; Context = context; Factory = factory; Method = method; }
/// <summary> /// Gets the return type for the given method /// </summary> /// <param name="method">The method symbol</param> /// <returns>The calculated return type, or null if one is not found</returns> public IType GetReturnType(IMethodSymbol method) { _model = _context.Compilation.GetSemanticModel(method.DeclaringSyntaxReferences[0].SyntaxTree); _handlerFactory = new ReturnSyntaxNodeHandlerFactory(_model, _context, method); // This only gets the first syntax, which is usually valid, but could be wrong for partial methods SyntaxNode node = method.DeclaringSyntaxReferences.FirstOrDefault().GetSyntax(); Visit(node); IType foundType = _candidates.LastOrDefault(); // Maybe select best type? OR merge types possibly. Probably a rare use case. if (foundType == null) { foundType = RoslynType.CreateType(method.ReturnType, _context); } return(foundType); }