ConfigurationManager.AppSettings[XXX]読み出しプロファイル


using System.Collections.Generic;
using System.Linq;

/* 
 * Crate By   CYJ  Date:2012-05-13
*/
namespace Doe.CdmsCommon
{
    public class AppSettings
    {
        private Dictionary settings;
        public AppSettings(Dictionary settings)
        {
            this.settings = settings;
        }
        public string this[string key]
        {
            get
            {
                if (settings.Keys.Contains(key))
                {
                    return this.settings[key];
                }
                return "";
            }
        }
    }
}

//===============ConfigurationManager ================

using System.Linq;
using System.Xml.Linq;
using System.IO;

/* 
 * Crate By   CYJ  Date:2012-05-13
*/
namespace Doe.CdmsCommon
{
   

 public static class ConfigurationManager
    {
        public static AppSettings AppSettings = null;
        static ConfigurationManager()
        {
            string configName = "ClientSettings.Config";
            string file = System.Windows.Forms.Application.StartupPath + "" + configName;
            if (File.Exists(file))
            {
                AppSettings = new AppSettings
                   (
                         Extensions.Descendants(XDocument.Load(file).Descendants("appSettings"), "add").Select
                          (
                                settingNode => new
                                {
                                    Key = settingNode.Attribute("key").Value,
                                    Value = settingNode.Attribute("value").Value
                                }
                           ).ToDictionary(s => s.Key, s => s.Value)
                  );
            }
            else
            {
                LogWrite.WriteLog(" plug_ins\\CSMenu ClientSettings.Config ");
            }

        }

    }
}