GetSection() public method

Get the config section by the name attribute.
public GetSection ( string sectionName ) : ConfigSection
sectionName string
return ConfigSection
        public static IList<ComponentGraph> LoadInstallerComponentGraphs()
        {
            Config deployments = new Config(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

            if (deployments == null)
            {
                throw new ApplicationException("could not load configuraiton");
            }
            List<string> sectionNames = deployments.SectionNames.ToList();
            if (sectionNames == null || !sectionNames.Any())
            {
                throw new ApplicationException("no sections deployments were found in the configuration file.");
            }

            if (sectionNames.Count() != deployments.Count)
            {
                throw new ArgumentException("error loading configuration, number of deployments vs sections name differ");
            }

            IList<ComponentGraph> componentGraphs = new List<ComponentGraph>(deployments.Count);

            for (int i = 0; i < deployments.Count; i++)
            {
                ComponentGraph component = new ComponentGraph();
                string deploymentName = sectionNames[i];
                Console.WriteLine("Reading Configuration group '{0}'", deploymentName);

                ConfigSection deployment = deployments.GetSection(deploymentName);
                if (deployment == null)
                {
                    Console.WriteLine("Error reading configuraiton group '{0}'", deploymentName);
                    continue;
                }

                IDictionary<string, string> globalValues = deployment.ValuesAsDictionary;

                component.Index = deployment.Index; //set index of all items for sorting later.
                List<ConfigSection> deploymentConfigCollections = deployment.Collections.GetCollections().ToList();
                for (int index = 0; index < deploymentConfigCollections.Count(); index++)
                {
                    ConfigSection installerSection = deploymentConfigCollections[index];
                    Console.WriteLine("Reading Configuration component section '{0}'", installerSection.Name);
                    var item = ComponentFactory.Create(globalValues, installerSection, index);
                    if (item != null)
                    {
                        component.Components.Add(item);
                    }
                }

                componentGraphs.Add(component);
            }

            return componentGraphs;
        }
        public static DeploymentStrategyComponentGraphBase Load(string deploymentName, string configPath, bool? forceLocal)
        {
            Config deployments = new Config(configPath);
            if(!deployments.SectionNames.Contains(deploymentName))
            {
                throw new ArgumentOutOfRangeException("deploymentName");
            }

            //got the deployment we want to create / setup
            ConfigSection deployment = deployments.GetSection(deploymentName);
            if (!deployment.ContainsKey("DestinationComputerName"))
            {
                throw new ArgumentOutOfRangeException("DestinationComputerName");
            }

            string destination = deployment["DestinationComputerName"];
            if (string.IsNullOrWhiteSpace(destination))
            {
                throw new ArgumentException("DestinationComputerName is empty");
            }

            DeploymentStrategyComponentGraphBase deploymentStrategyComponentGraph;

            if (destination.ToLower().Contains("localhost") || (forceLocal.HasValue && forceLocal.Value))
            {
                deploymentStrategyComponentGraph = deployment.Create<LocalDeploymentStrategyComponentGraphBase>();
            }
            else
            {
                deploymentStrategyComponentGraph = deployment.Create<RemoteDeploymentStrategyComponentGraphBase>();
            }

            if (!deployment.ContainsSubCollections)
            {
                return deploymentStrategyComponentGraph;
            }

            //create the actions for the deployment.
            CreateActions(deploymentStrategyComponentGraph, deployment, GetMsdeployLocations(deployment));

            //update the username and password if given.
            var remoteDetails = GetRemoteDetails(deployment);
            if (remoteDetails != null)
            {
                foreach (var action in deploymentStrategyComponentGraph.Actions)
                {
                    action.DestinationUserName = remoteDetails.DestinationUserName;
                    action.DestinationPassword = remoteDetails.DestinationPassword;
                    action.AuthType = remoteDetails.AuthType;
                }
            }

            return deploymentStrategyComponentGraph;
        }
        /// <summary>
        /// Loads the config object and gets two different configSections to be able to get variables key values across both sections.
        /// </summary>
        public LoadingMultipleConfigSections()
        {
            Config config = new Config("myCustomGroup/mysection");

            foreach (var sectionName in config.SectionNames)
            {
                Console.WriteLine("section name key found: " + sectionName);
            }

            ConfigSection configSection1 = config.GetSection("client1");
            ConfigSection configSection2 = config.GetSection("client2");

            string myVal1 = configSection1["key2"];
            string myVal2 = configSection2["key2"];

            Console.WriteLine("loaded two client objects, client1 and client2");
            Console.WriteLine("found values for both, each using the same key, ('key2')");
            Console.WriteLine("client 1 key val: " + myVal1);
            Console.WriteLine("client 2 key val: " + myVal2);
            Console.WriteLine("");
        }