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

类库从自带的配置文件中获取信息(DLL文件 获取 DLL文件自带的配置信息) z

时间:2014-12-21 19:25:26      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

http://blog.csdn.net/shuaishifu/article/details/19602059

类库调用自身所带的配置文件中的配置信息,而不是读取应用程序所带的配置信息。代码如下:

private Configuration GetConfig()
        {
            //获取调用当前正在执行的方法的方法的 Assembly
            Assembly assembly = Assembly.GetCallingAssembly();
            string path = string.Format("{0}.config", assembly.Location);

            if (File.Exists(path) == false)
            {
                string msg = string.Format("{0}路径下的文件未找到 ", path);
                throw new FileNotFoundException(msg);
            }

            try
            {
                ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
                configFile.ExeConfigFilename = path;
                Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);

                return config;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

 

类库从自带的配置文件中获取信息(DLL文件 获取 DLL文件自带的配置信息) z

标签:

原文地址:http://www.cnblogs.com/zeroone/p/4176892.html

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