/// <summary>
        /// Generate CodeDom of the client API for ApiDescriptions.
        /// </summary>
        /// <param name="descriptions">Web Api descriptions exposed by Configuration.Services.GetApiExplorer().ApiDescriptions</param>
        public void CreateCodeDom(WebApiDescription[] descriptions)
        {
            if (descriptions == null)
            {
                throw new ArgumentNullException("descriptions");
            }

            GenerateCsFromPoco();
            //controllers of ApiDescriptions (functions) grouped by namespace
            var controllersGroupByNamespace = descriptions.Select(d => d.ActionDescriptor.ControllerDescriptor).Distinct().GroupBy(d => d.ControllerType.Namespace);

            //Create client classes mapping to controller classes
            foreach (var grouppedControllerDescriptions in controllersGroupByNamespace)
            {
                var clientNamespaceText = grouppedControllerDescriptions.Key + ".Client";
                var clientNamespace     = new CodeNamespace(clientNamespaceText);
                targetUnit.Namespaces.Add(clientNamespace);//namespace added to Dom

                clientNamespace.Imports.AddRange(new CodeNamespaceImport[] {
                    new CodeNamespaceImport("System"),
                    new CodeNamespaceImport("System.Collections.Generic"),
                    new CodeNamespaceImport("System.Threading.Tasks"),
                    new CodeNamespaceImport("System.Net.Http"),
                    new CodeNamespaceImport("Newtonsoft.Json"),
                });

                var newClassesCreated = grouppedControllerDescriptions.Select(d =>
                {
                    var controllerFullName = d.ControllerType.Namespace + "." + d.ControllerName;
                    if (codeGenParameters.ApiSelections.ExcludedControllerNames != null && codeGenParameters.ApiSelections.ExcludedControllerNames.Contains(controllerFullName))
                    {
                        return(null);
                    }

                    return(CreateControllerClientClass(clientNamespace, d.ControllerName));
                }
                                                                              ).ToArray();//add classes into the namespace
            }

            foreach (var d in descriptions)
            {
                var controllerNamespace = d.ActionDescriptor.ControllerDescriptor.ControllerType.Namespace;
                var controllerName      = d.ActionDescriptor.ControllerDescriptor.ControllerName;
                var controllerFullName  = controllerNamespace + "." + controllerName;
                if (codeGenParameters.ApiSelections.ExcludedControllerNames != null && codeGenParameters.ApiSelections.ExcludedControllerNames.Contains(controllerFullName))
                {
                    continue;
                }

                var existingClientClass = LookupExistingClass(controllerNamespace, controllerName);
                System.Diagnostics.Trace.Assert(existingClientClass != null);

                var apiFunction = ClientApiFunctionGen.Create(sharedContext, d, poco2CsGen, this.codeGenParameters.ClientApiOutputs.StringAsString, true);
                existingClientClass.Members.Add(apiFunction);
                if (ForBothAsyncAndSync)
                {
                    existingClientClass.Members.Add(ClientApiFunctionGen.Create(sharedContext, d, poco2CsGen, this.codeGenParameters.ClientApiOutputs.StringAsString, false));
                }
            }
        }
        /// <summary>
        /// Generate CodeDom of the client API for ApiDescriptions.
        /// </summary>
        /// <param name="descriptions">Web Api descriptions exposed by Configuration.Services.GetApiExplorer().ApiDescriptions</param>
        public void CreateCodeDom(WebApiDescription[] descriptions)
        {
            if (descriptions == null)
            {
                throw new ArgumentNullException(nameof(descriptions));
            }

            GenerateCsFromPoco();
            //controllers of ApiDescriptions (functions) grouped by namespace
            var controllersGroupByNamespace = descriptions.Select(d => d.ActionDescriptor.ControllerDescriptor)
                                              .Distinct()
                                              .GroupBy(d => d.ControllerType.Namespace)
                                              .OrderBy(g => g.Key);// order by namespace

            //Create client classes mapping to controller classes
            foreach (var grouppedControllerDescriptions in controllersGroupByNamespace)
            {
                var clientNamespaceText = grouppedControllerDescriptions.Key + CodeGenParameters.ClientApiOutputs.CSClientNamespaceSuffix;
                var clientNamespace     = new CodeNamespace(clientNamespaceText);
                TargetUnit.Namespaces.Add(clientNamespace);                //namespace added to Dom

                clientNamespace.Imports.AddRange(new CodeNamespaceImport[] {
                    new CodeNamespaceImport("System"),
                    new CodeNamespaceImport("System.Linq"),
                    new CodeNamespaceImport("System.Collections.Generic"),
                    new CodeNamespaceImport("System.Threading.Tasks"),
                    new CodeNamespaceImport("System.Net.Http"),
                    new CodeNamespaceImport("Newtonsoft.Json"),
                });

                if (CodeGenParameters.ClientApiOutputs.UseEnsureSuccessStatusCodeEx)
                {
                    clientNamespace.Imports.Add(new CodeNamespaceImport("Fonlow.Net.Http"));
                }

                var newClassesCreated = grouppedControllerDescriptions
                                        .OrderBy(d => d.ControllerName)
                                        .Select(d =>
                {
                    var controllerFullName = d.ControllerType.Namespace + "." + d.ControllerName;
                    if (CodeGenParameters.ApiSelections.ExcludedControllerNames != null && CodeGenParameters.ApiSelections.ExcludedControllerNames.Contains(controllerFullName))
                    {
                        return(null);
                    }

                    string containerClassName = GetContainerClassName(d.ControllerName);
                    return(CreateControllerClientClass(clientNamespace, containerClassName));
                }
                                                )
                                        .ToArray();//add classes into the namespace
            }

            foreach (var d in descriptions)
            {
                var controllerNamespace = d.ActionDescriptor.ControllerDescriptor.ControllerType.Namespace;
                var controllerName      = d.ActionDescriptor.ControllerDescriptor.ControllerName;
                var controllerFullName  = controllerNamespace + "." + controllerName;
                if (CodeGenParameters.ApiSelections.ExcludedControllerNames != null && CodeGenParameters.ApiSelections.ExcludedControllerNames.Contains(controllerFullName))
                {
                    continue;
                }

                var existingClientClass = LookupExistingClass(controllerNamespace, GetContainerClassName(controllerName));
                System.Diagnostics.Trace.Assert(existingClientClass != null);

                var apiFunction = ClientApiFunctionGen.Create(d, poco2CsGen, this.CodeGenParameters.ClientApiOutputs, true);
                existingClientClass.Members.Add(apiFunction);
                if (ForBothAsyncAndSync)
                {
                    existingClientClass.Members.Add(ClientApiFunctionGen.Create(d, poco2CsGen, this.CodeGenParameters.ClientApiOutputs, false));
                }
            }

            if (CodeGenParameters.ClientApiOutputs.UseEnsureSuccessStatusCodeEx && CodeGenParameters.ClientApiOutputs.IncludeEnsureSuccessStatusCodeExBlock)
            {
                CreateDummyOfEnsureSuccessStatusCodeEx();
            }
        }