Esempio n. 1
0
        public object GetSection(string configKey)
        {
            // get the section from the default location (web.config or app.config)
            object section = clientConfigSystem.GetSection(configKey);

            switch (configKey)
            {
            case "appSettings":
                if (this.appsettings != null)
                {
                    return(this.appsettings);
                }

                if (section is NameValueCollection)
                {
                    // create a new collection because the underlying collection is read-only
                    var cfg = new NameValueCollection();
                    NameValueCollection localSettings = (NameValueCollection)section;
                    foreach (string key in localSettings)
                    {
                        cfg.Add(key, localSettings[key]);
                    }

                    // merge the settings from core with the local appsettings
                    this.appsettings = cfg.Merge(ConfigurationManager.AppSettings);
                    section          = this.appsettings;
                }

                break;

            case "connectionStrings":
                if (this.connectionStrings != null)
                {
                    return(this.connectionStrings);
                }

                // create a new collection because the underlying collection is read-only
                var cssc = new ConnectionStringSettingsCollection();

                // copy the existing connection strings into the new collection
                foreach (ConnectionStringSettings connectionStringSetting in ((ConnectionStringsSection)section).ConnectionStrings)
                {
                    cssc.Add(connectionStringSetting);
                }

                // merge the settings from core with the local connectionStrings
                cssc = cssc.Merge(ConfigurationManager.ConnectionStrings);

                ConnectionStringsSection connectionStringsSection = new ConnectionStringsSection();

                foreach (ConnectionStringSettings connectionStringSetting in cssc)
                {
                    connectionStringsSection.ConnectionStrings.Add(connectionStringSetting);
                }

                this.connectionStrings = connectionStringsSection;
                section = this.connectionStrings;
                break;
            }

            return(section);
        }