Esempio n. 1
0
        public static List <SyntaxNodeOrToken> TransformMultipleComplexTypeArguments(List <SyntaxNodeOrToken> arguments,
                                                                                     SeparatedSyntaxList <ParameterSyntax> wcfParameters, string wcfMethodName)
        {
            var complexParameters = MultipleComplexTypesGenerator.FindMultipleComplexTypesOrOutKeyword(wcfParameters);

            if (!complexParameters.Any())
            {
                return(arguments);
            }

            // replace all complex type arguments with complex type class properties
            // if any arguments already have 'out' keyword then will be ignored
            var newArguments = arguments
                               .Select(nodeOrToken =>
            {
                var argument   = (ArgumentSyntax)nodeOrToken;
                var isArgument = argument != null;

                if (!isArgument)
                {
                    return(nodeOrToken);
                }

                var argumentName = argument
                                   .NormalizeWhitespace()
                                   .ToFullString();

                var isComplexArgument = complexParameters
                                        .Select(parameter => parameter.Identifier.ValueText)
                                        .Contains(argumentName);

                if (!isComplexArgument)
                {
                    return(argument);
                }

                var complexTypeArgumentName = ComplexTypeNamesMapper.MapToComplexTypeArgument(wcfMethodName, argumentName);
                var complexTypeArgument     = SyntaxFactory.Argument(SyntaxFactory.IdentifierName(complexTypeArgumentName));

                return(complexTypeArgument);
            })
                               .ToList();

            return(newArguments);
        }
Esempio n. 2
0
        private static IEnumerable <StatementSyntax> CreateEndStatements(IEnumerable <string> argumentNames, string wcfMethodName)
        {
            var resultStatement = $"{ComplexTypeNamesMapper.MapToComplexTypeArgument(wcfMethodName, "Result")} = result;";

            var endStatements = argumentNames
                                .Select(argumentName =>
            {
                var complexTypeArgument = ComplexTypeNamesMapper.MapToComplexTypeArgument(wcfMethodName, argumentName);

                var statement            = $"{complexTypeArgument} = {argumentName};";
                var statementDeclaration = SyntaxFactory.ParseStatement(statement);

                return(statementDeclaration);
            })
                                .Prepend(SyntaxFactory.ParseStatement(resultStatement));

            return(endStatements);
        }