public static string CreateMultipleComplexTypesClassInstance(MethodDeclarationSyntax wcfClientMethod, string serviceComplexTypeParamName, IEnumerable <MethodDeclarationSyntax> wcfServiceMethods) { // handle if method has two or more (i.e. "multiple") complex types parameters var wcfServiceMethod = MethodsGenerator.FindWcfServiceMethod(wcfClientMethod, wcfServiceMethods); var wcfServiceParameters = wcfServiceMethod .ParameterList .Parameters; var multipleComplexParameters = MultipleComplexTypesGenerator.FindMultipleComplexTypesOrOutKeyword(wcfServiceParameters); // get the param names and use as anonymous class property names var properties = multipleComplexParameters.Any() ? multipleComplexParameters .Select(parameter => { var name = parameter.Identifier.ToFullString(); return(name); }) .Aggregate((name1, name2) => $"{name1},{name2}") : ""; // create anonymous class instance with complex type properties var hasComplexTypeProperties = !string.IsNullOrEmpty(properties); var classInstance = hasComplexTypeProperties ? $@"var {serviceComplexTypeParamName} = new {{{properties}}};" : ""; return(classInstance); }
public static string CreateInterfaceParameterNameMappings(MethodDeclarationSyntax wcfClientMethod, IEnumerable <MethodDeclarationSyntax> wcfServiceMethods) { // sometimes interface methods' parameter names don't match names belonging to derived classes // therefore, find and map them var wcfServiceMethod = MethodsGenerator.FindWcfServiceMethod(wcfClientMethod, wcfServiceMethods); var mappings = BuildParameterMappings(wcfClientMethod, wcfServiceMethod); var mappingsCode = mappings.Any() ? mappings .Select(map => $"var {map.serviceParameterName} = {map.clientParameterName};") .Aggregate((map1, map2) => $"{map1}\n\r{map2}") : ""; return(mappingsCode); }