Example #1
0
        public static async Task <string> CreateComplexTypeClass(MethodDeclarationSyntax wcfMethod, string methodName, bool isActiveWcfMethod)
        {
            if (!isActiveWcfMethod)
            {
                return("");
            }

            var parameters = wcfMethod.ParameterList.Parameters;

            // add return type as class property if has 'out' keyword
            if (!OutKeywordGenerator.AnyHaveOutKeyword(parameters))
            {
                return("");
            }

            // create complex class
            var className = ComplexTypeNamesMapper.MapToClientComplexClassName(methodName);
            var complexClassDeclaration = await MultipleComplexTypesGenerator.CreateClassFromComplexTypes(parameters, className);

            // create return type property
            var wcfReturnType          = wcfMethod.ReturnType.NormalizeWhitespace().ToFullString();
            var returnTypePropertyCode = $"public {wcfReturnType} Result {{ get; set;}}";
            var returnTypeProperty     = (await CodeParser.ConvertToMemberDeclarations(returnTypePropertyCode)).Single();

            // add return type property to complex class
            var members = complexClassDeclaration.Members.Add(returnTypeProperty);

            complexClassDeclaration = complexClassDeclaration.WithMembers(members);
            var complexTypeClass = complexClassDeclaration?.NormalizeWhitespace().ToFullString();

            return(complexTypeClass);
        }
Example #2
0
        public static BlockSyntax TransformBlockWithOutKeyword(BlockSyntax block, SeparatedSyntaxList <ParameterSyntax> wcfParameters,
                                                               IEnumerable <SyntaxNodeOrToken> arguments, string methodName)
        {
            if (!OutKeywordGenerator.AnyHaveOutKeyword(wcfParameters))
            {
                return(block);
            }

            block = AddStatementsForOutKeyword(block, arguments, wcfParameters, methodName);
            block = TransformReturnStatement(block, methodName);

            return(block);
        }
Example #3
0
        public static string TransformOutKeywordReturnType(string wcfReturnType, SeparatedSyntaxList <ParameterSyntax> wcfParameters, string wcfMethodName)
        {
            var isVoidReturnType = wcfReturnType == "void";

            if (!OutKeywordGenerator.AnyHaveOutKeyword(wcfParameters) || isVoidReturnType)
            {
                return(wcfReturnType);
            }

            var complexVariableName = ComplexTypeNamesMapper.MapToServiceComplexClassType(wcfMethodName);

            var returnType = complexVariableName;

            return(returnType);
        }
Example #4
0
        public static string TransformMethodBlockWithOutKeywords(string block, MethodDeclarationSyntax wcfMethod, bool isActiveWcfMethod)
        {
            if (!isActiveWcfMethod)
            {
                return(block);
            }

            var wcfParameters = wcfMethod
                                .ParameterList
                                .Parameters;

            var hasOutKeyword = OutKeywordGenerator.AnyHaveOutKeyword(wcfParameters);

            if (!hasOutKeyword)
            {
                return(block);
            }

            var blockDeclaration = (BlockSyntax)SyntaxFactory.ParseStatement($"{block}");
            var parameterNames   = GetParameterNamesWithOutKeywords(wcfParameters);

            // add to start of method block
            var firstStatementIndex = 0;
            var startStatements     = CreateStartStatements(parameterNames, wcfParameters);
            var statements          = blockDeclaration.Statements.InsertRange(firstStatementIndex, startStatements);

            // add before end (i.e. before the return statement) of method block
            var oldStatement  = FindStatementToReplace(statements);
            var endStatements = CreateEndStatements(parameterNames, wcfParameters, wcfMethod);

            statements = statements.ReplaceRange(oldStatement, endStatements);

            // finialize block
            blockDeclaration = blockDeclaration.WithStatements(statements);
            block            = blockDeclaration.ToFullString();

            return(block);
        }
Example #5
0
        public static ClassDeclarationSyntax TransformComplexClassWithOutKeyword(ClassDeclarationSyntax complexClass, SeparatedSyntaxList <ParameterSyntax> wcfParameters, string wcfReturnType)
        {
            if (!OutKeywordGenerator.AnyHaveOutKeyword(wcfParameters))
            {
                return(complexClass);
            }

            var classProperties = complexClass.Members.OfType <PropertyDeclarationSyntax>();

            var outKeywordProperty            = $"public {wcfReturnType} Result {{ get; set;}}";
            var outKeywordPropertyDeclaration = SyntaxFactory.ParseCompilationUnit(outKeywordProperty)
                                                .DescendantNodes()
                                                .OfType <PropertyDeclarationSyntax>()
                                                .First();

            var newProperties = new List <PropertyDeclarationSyntax>();

            newProperties.AddRange(classProperties);
            newProperties.Add(outKeywordPropertyDeclaration);

            var newComplexClass = complexClass.WithMembers(SyntaxFactory.List <MemberDeclarationSyntax>(newProperties));

            return(newComplexClass);
        }