예제 #1
0
        protected override ImmutableArray <ParameterInfo> GetParameterInfos(
            InvocationExpressionSyntax node,
            IMethodSymbol symbol)
        {
            bool isReduced = symbol.MethodKind == MethodKind.ReducedExtension;

            ImmutableArray <IParameterSymbol> parameters = symbol.Parameters;

            List <ParameterInfo> parameterInfos = null;

            SeparatedSyntaxList <ArgumentSyntax> arguments = node.ArgumentList.Arguments;

            foreach (ArgumentSyntax argument in arguments)
            {
                IParameterSymbol parameterSymbol = DetermineParameterHelper.DetermineParameter(argument, arguments, parameters);

                if (parameterSymbol != null)
                {
                    var parameterInfo = new ParameterInfo(parameterSymbol, argument.Expression);

                    (parameterInfos ??= new List <ParameterInfo>()).Add(parameterInfo);
                }
                else
                {
                    return(default);
예제 #2
0
 public static ImmutableArray <ITypeSymbol> DetermineParameterTypes(
     ArgumentSyntax argument,
     SemanticModel semanticModel,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(DetermineParameterHelper.DetermineParameterTypes(argument, semanticModel, cancellationToken));
 }
예제 #3
0
 public static IParameterSymbol DetermineParameter(
     this SemanticModel semanticModel,
     AttributeArgumentSyntax attributeArgument,
     bool allowParams    = false,
     bool allowCandidate = false,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(DetermineParameterHelper.DetermineParameter(attributeArgument, semanticModel, allowParams, allowCandidate, cancellationToken));
 }
예제 #4
0
        protected override ImmutableArray <ParameterInfo> GetParameterInfos(
            InvocationExpressionSyntax node,
            IMethodSymbol symbol)
        {
            bool isReduced = symbol.MethodKind == MethodKind.ReducedExtension;

            ImmutableArray <IParameterSymbol> parameters = symbol.Parameters;

            List <ParameterInfo> parameterInfos = null;

            SeparatedSyntaxList <ArgumentSyntax> arguments = node.ArgumentList.Arguments;

            foreach (ArgumentSyntax argument in arguments)
            {
                IParameterSymbol parameterSymbol = DetermineParameterHelper.DetermineParameter(argument, arguments, parameters);

                if (parameterSymbol != null)
                {
                    var parameterInfo = new ParameterInfo(parameterSymbol, argument.Expression);

                    (parameterInfos ?? (parameterInfos = new List <ParameterInfo>())).Add(parameterInfo);
                }
                else
                {
                    return(default(ImmutableArray <ParameterInfo>));
                }
            }

            foreach (IParameterSymbol parameterSymbol in parameters)
            {
                if (parameterInfos == null ||
                    parameterInfos.FindIndex(f => f.ParameterSymbol.Equals(parameterSymbol)) == -1)
                {
                    if (parameterSymbol.HasExplicitDefaultValue)
                    {
                        var parameterInfo = new ParameterInfo(parameterSymbol, null);

                        (parameterInfos ?? (parameterInfos = new List <ParameterInfo>())).Add(parameterInfo);
                    }
                    else
                    {
                        return(default(ImmutableArray <ParameterInfo>));
                    }
                }
            }

            if (isReduced)
            {
                var memberAccess = (MemberAccessExpressionSyntax)node.Expression;

                ExpressionSyntax expression = memberAccess.Expression;

                SyntaxNode nodeIncludingConditionalAccess = node.WalkUp(SyntaxKind.ConditionalAccessExpression);

                if (nodeIncludingConditionalAccess != node)
                {
                    int startIndex = expression.Span.End - nodeIncludingConditionalAccess.SpanStart;
                    expression = SyntaxFactory.ParseExpression(nodeIncludingConditionalAccess.ToString().Remove(startIndex));
                }

                var parameterInfo = new ParameterInfo(symbol.ReducedFrom.Parameters[0], expression.TrimTrivia(), isThis: true);

                (parameterInfos ?? (parameterInfos = new List <ParameterInfo>())).Add(parameterInfo);
            }

            return((parameterInfos != null)
                ? parameterInfos.ToImmutableArray()
                : ImmutableArray <ParameterInfo> .Empty);
        }
        protected override ImmutableArray <ParameterInfo> GetParameterInfos(
            InvocationExpressionSyntax node,
            IMethodSymbol symbol)
        {
            bool isReduced = symbol.MethodKind == MethodKind.ReducedExtension;

            if (isReduced)
            {
                symbol = symbol.GetConstructedReducedFrom();
            }

            ImmutableArray <IParameterSymbol> parameters = symbol.Parameters;

            if (isReduced)
            {
                parameters = parameters.RemoveAt(0);
            }

            List <ParameterInfo> parameterInfos = null;

            SeparatedSyntaxList <ArgumentSyntax> arguments = node.ArgumentList.Arguments;

            foreach (ArgumentSyntax argument in arguments)
            {
                IParameterSymbol parameterSymbol = DetermineParameterHelper.DetermineParameter(argument, arguments, parameters);

                if (parameterSymbol != null)
                {
                    var parameterInfo = new ParameterInfo(parameterSymbol, argument.Expression);

                    (parameterInfos ?? (parameterInfos = new List <ParameterInfo>())).Add(parameterInfo);
                }
                else
                {
                    return(default(ImmutableArray <ParameterInfo>));
                }
            }

            foreach (IParameterSymbol parameterSymbol in parameters)
            {
                if (parameterInfos == null ||
                    parameterInfos.FindIndex(f => f.ParameterSymbol.Equals(parameterSymbol)) == -1)
                {
                    if (parameterSymbol.HasExplicitDefaultValue)
                    {
                        var parameterInfo = new ParameterInfo(parameterSymbol, null);

                        (parameterInfos ?? (parameterInfos = new List <ParameterInfo>())).Add(parameterInfo);
                    }
                    else
                    {
                        return(default(ImmutableArray <ParameterInfo>));
                    }
                }
            }

            if (isReduced)
            {
                var memberAccess = (MemberAccessExpressionSyntax)node.Expression;

                var parameterInfo = new ParameterInfo(symbol.Parameters[0], memberAccess.Expression.TrimTrivia());

                (parameterInfos ?? (parameterInfos = new List <ParameterInfo>())).Add(parameterInfo);
            }

            return((parameterInfos != null)
                ? parameterInfos.ToImmutableArray()
                : ImmutableArray <ParameterInfo> .Empty);
        }