我在使用IConfiguration时遇到问题 [英] I have a problem using IConfiguration

查看:504
本文介绍了我在使用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,但我不知道为什么会因此代码而收到此错误
这是我的代码,我是WEF用户,不知道该代码收到此错误.



THIS IS MY CODE AND I AM USING WEF AND I DO NOT KNOW WHY I GET THIS ERROR FOR THIS CODE
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.
It says that "Type or namespace (IConfiguration) cannot be found"
Please help me with this.
Thank you.

推荐答案

将文本输入光标放在"IConfiguration"一词中. 看一下单词的左手边. "I"下方将有一个空心的蓝色小条.
将鼠标悬停在该栏上,将出现一个下拉列表.打开下拉菜单,然后查看选项.
如果它们仅由"Generate Class"和"Generate Type"组成,则需要添加对包含IConfiguration的程序集的引用.
如果那里还有其他任何东西,那么使用它应该可以解决您的问题.
Place your text entry cursor in the word "IConfiguration".
Look at the left hand end of the word. There will be a small hollow blue bar under the "I".
Hover the mouse over this bar, and a dropdown will appear. Open the dropdown and look at the options.
If they consist of just "Generate Class" and "Generate Type" they you need to add a reference to the assembly containing IConfiguration.
If there is anything else there, then using that should solve your problem.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆