码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-09-19 17:53:51      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

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

    }
}

 

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

标签:

原文地址:http://www.cnblogs.com/zoumin123/p/5885854.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!