首页 > 代码库 > 库类读取和库相同名的配置文件

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

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);                   }    }}

 

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