Beispiel #1
0
        private bool IsSpecificArgumentInSpecificMethod(CSharpCodeCompletionContext context, out ICSharpLiteralExpression stringLiteral,
                                                        Func <IInvocationExpression, bool> methodChecker, Func <IArgumentList, ICSharpArgument, bool> argumentChecker)
        {
            stringLiteral = null;
            var nodeInFile = context.NodeInFile as ITokenNode;

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

            var possibleInvocationExpression = nodeInFile.Parent;

            if (possibleInvocationExpression is ICSharpLiteralExpression literalExpression)
            {
                if (!literalExpression.Literal.IsAnyStringLiteral())
                {
                    return(false);
                }

                var argument     = CSharpArgumentNavigator.GetByValue(literalExpression);
                var argumentList = ArgumentListNavigator.GetByArgument(argument);
                if (argument == null || argumentList == null)
                {
                    return(false);
                }

                if (argumentChecker(argumentList, argument))
                {
                    stringLiteral = literalExpression;
                    possibleInvocationExpression = InvocationExpressionNavigator.GetByArgument(argument);
                }
            }


            if (possibleInvocationExpression is IInvocationExpression invocationExpression)
            {
                if (methodChecker(invocationExpression))
                {
                    return(true);
                }
            }

            stringLiteral = null;
            return(false);
        }
        private IDeclaredType[] GetParameterTypes()
        {
            var node         = Reference.GetTreeNode();
            var argument     = CSharpArgumentNavigator.GetByValue(node as ICSharpLiteralExpression);
            var argumentList = ArgumentListNavigator.GetByArgument(argument);
            var invocation   = InvocationExpressionNavigator.GetByArgumentList(argumentList);

            if (invocation?.Reference?.Resolve().DeclaredElement?.ShortName
                .Equals("StartCoroutine") == true && argumentList?.Arguments.Count > 1)
            {
                var secondArgument = argumentList.NotNull("argumentList != null").Arguments[1];
                if (secondArgument.Value?.Type() is IDeclaredType type)
                {
                    return(new[] { type });
                }
            }

            return(new IDeclaredType[] { });
        }