Esempio n. 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);
        }