库类读取和库相同名的配置文件

using System;
using System.Configuration;
using System.Reflection;

namespace ceshi
{
    public class Class1
    {
        public static readonly string Token;

        public static readonly string CorpID;

        public static readonly string EncodingAESKey;

        public static readonly string Secret;

        public static readonly int AppID;
        public static string Value(string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return "";
            }
            return config.AppSettings.Settings[key].Value;
        }
        private static Configuration config = null;
        static Class1()
        {
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = new Uri((Assembly.GetExecutingAssembly()).CodeBase).LocalPath + ".config";
            config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
             Token = "hours";
             CorpID = config.AppSettings.Settings["CorpID"].Value;
             EncodingAESKey = config.AppSettings.Settings["EncodingAESKey"].Value;
             Secret = config.AppSettings.Settings["Secret"].Value;
             AppID = Convert.ToInt32(config.AppSettings.Settings["AppID"].Value);
           
        }

    }
}

 

posted on 2016-09-19 17:05  邹敏向日葵  阅读(134)  评论(0编辑  收藏  举报

导航