本文介绍了我在使用IConfiguration时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//Fisharoo/Components/Configuration.cs
using System;
using System.ComponentModel.Composition;
using System.Configuration;
using Fisharoo.Interfaces;
namespace Fisharoo.Components
{
    [Export(typeof(IConfiguration))]
        public class Configuration : IConfiguration
        {
            public object GetConfigurationSetting(Type expectedType,
            string key)
                {
                    string value = ConfigurationManager.AppSettings.Get(key);
                    if (value == null)
                        {
                            throw new Exception(string.Format("AppSetting: {0} is not configured.", key));
                        }
                    try
                        {
                        if (expectedType.Equals(typeof(int)))
                            {
                                return int.Parse(value);
                            }
                        if (expectedType.Equals(typeof(string)))
                            {
                                return value;
                            }
                        throw new Exception("Type not supported.");
                        }
                    catch (Exception ex)
                        {
                            throw new Exception(string.Format("Config key:{0} was expected to be of type {1} but was not.", key, expectedType), ex);
                        }
                }
        }
}




这是我的代码,我是WEF用户,不知道该代码收到此错误.




This is my code and I am usig WEF and I do not know wht I get this Error for this code.

//Fisharoo/Components/Configuration.cs


    [Export(typeof(IConfiguration))]
        public class Configuration : IConfiguration







它说找不到类型或名称空间(IConfiguration)"
请帮助我.
谢谢.







It says that "Type or namespace (IConfiguration) cannot be found"
Please help me with this.
Thank you.

推荐答案


这篇关于我在使用IConfiguration时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 09:09