示例#1
0
        /// <summary>
        /// Tries to get the method from the given type and virtual call.
        /// </summary>
        /// <param name="method">Method</param>
        /// <param name="type">Type</param>
        /// <param name="virtualCall">Virtual call</param>
        /// <param name="context">AnalysisContext</param>
        /// <returns>Boolean value</returns>
        private static bool TryGetMethodFromType(out MethodDeclarationSyntax method, ITypeSymbol type,
                                                 InvocationExpressionSyntax virtualCall, AnalysisContext context)
        {
            method = null;

            var definition = SymbolFinder.FindSourceDefinitionAsync(type, context.Solution).Result;

            if (definition == null)
            {
                return(false);
            }

            var calleeClass = definition.DeclaringSyntaxReferences.First().GetSyntax()
                              as ClassDeclarationSyntax;

            foreach (var m in calleeClass.ChildNodes().OfType <MethodDeclarationSyntax>())
            {
                if (m.Identifier.ValueText.Equals(context.GetCallee(virtualCall)))
                {
                    method = m;
                    break;
                }
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// Tries to get the method from the given type and virtual call.
        /// </summary>
        /// <param name="method">Method</param>
        /// <param name="type">Type</param>
        /// <param name="virtualCall">Virtual call</param>
        /// <param name="context">AnalysisContext</param>
        /// <returns>Boolean</returns>
        private static bool TryGetMethodFromType(out MethodDeclarationSyntax method, ITypeSymbol type,
            InvocationExpressionSyntax virtualCall, AnalysisContext context)
        {
            method = null;

            var definition = SymbolFinder.FindSourceDefinitionAsync(type, context.Solution).Result;
            if (definition == null)
            {
                return false;
            }

            var calleeClass = definition.DeclaringSyntaxReferences.First().GetSyntax()
                as ClassDeclarationSyntax;
            foreach (var m in calleeClass.ChildNodes().OfType<MethodDeclarationSyntax>())
            {
                if (m.Identifier.ValueText.Equals(context.GetCallee(virtualCall)))
                {
                    method = m;
                    break;
                }
            }

            return true;
        }