Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何跟踪ConfigurationManager.AppSettings的来源?_C#_Configuration - Fatal编程技术网

C# 如何跟踪ConfigurationManager.AppSettings的来源?

C# 如何跟踪ConfigurationManager.AppSettings的来源?,c#,configuration,C#,Configuration,我的AppModel基类上有以下代码: public string GetParameter(string key) { //Allow local config file to override DB setting string retval = ConfigurationManager.AppSettings[key]; if (!string.IsNullOrEmpty(retval

我的AppModel基类上有以下代码:

        public string GetParameter(string key)
        {
            //Allow local config file to override DB setting
            string retval = ConfigurationManager.AppSettings[key];

            if (!string.IsNullOrEmpty(retval))
            {
                Trace.TraceInformation("{0} from ConfigurationManager.AppSettings is '{1}'", key, retval);
                return retval;
            }

            //No setting in config file - check for ProfileParameter from DB
            Parameters.TryGetValue(key, out retval);
            Trace.TraceInformation("{0} from ProfileParameter is '{1}'", key, retval);
            return retval;          
        }

我在Excel中看到一个参数值加载项来自ConfigurationManager.AppSettings,但我不知道它在哪里找到参数-ConfigurationManager正在使用的配置文件的路径是什么?有没有办法向ConfigurationManager询问其知识来源?

在VS(设置>添加新项)中创建配置对象值时,会为其分配一个默认值(等于创建时的值)。
当未找到/未加载/etc配置文件时,将使用默认值

在项目的Settings.Designer.cs文件中查看设置上方的属性
global::System.Configuration.DefaultSettingValueAttribute

测试项目中的设置示例:

[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("This is my default string value")] // << This is what you are looking for
public string TestSetting
{
  get
  {
    return ((string)(this["TestSetting"]));
  }
}

[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]  // << This is what you are looking for
public bool AnotherSetting
{
  get
  {
    return ((bool)(this["AnotherSetting"]));
  }
  set
  {
    this["AnotherSetting"] = value;
  }
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]

[global::System.Configuration.DefaultSettingValueAttribute(“这是我的默认字符串值”)]/在VS(设置>添加新项)中创建配置对象值时,会为其分配一个默认值(等于创建时的值)。
当未找到/未加载/etc配置文件时,将使用默认值

在项目的Settings.Designer.cs文件中查看设置上方的属性
global::System.Configuration.DefaultSettingValueAttribute

测试项目中的设置示例:

[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("This is my default string value")] // << This is what you are looking for
public string TestSetting
{
  get
  {
    return ((string)(this["TestSetting"]));
  }
}

[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]  // << This is what you are looking for
public bool AnotherSetting
{
  get
  {
    return ((bool)(this["AnotherSetting"]));
  }
  set
  {
    this["AnotherSetting"] = value;
  }
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[全局::System.Diagnostics.DebuggerNonUserCodeAttribute()]

[global::System.Configuration.DefaultSettingValueAttribute(“这是我的默认字符串值”)]/
ConfigurationManager.AppSettings
指编译应用程序时应存在于项目根文件夹中的
app.config
,app.config变成了.config,但我正在为Excel构建一个加载项-它应该是Excel.exe.config吗?重复“有没有办法向ConfigurationManager询问它的知识来源?”
ConfigurationManager。AppSettings
指的是应存在于项目根文件夹中的
app.config
(即,所有其他*.cs文件都存在的地方)编译应用程序时,app.config将变为.config,但我正在为Excel构建一个加载项-它是否应为Excel.exe.config?重复“是否有方法向ConfigurationManager询问其知识来源?”我知道有两种方法可以进行开箱即用的配置:您描述的“设置”是通过Properties.Settings.Default访问的,我目前没有使用它(跟踪实际的配置文件,必须调用Properties.Settings.Default.Upgrade()让我头疼!);另一种方法是创建一个App.Config,其中包含通过ConfigurationManager.AppSettings编译和访问应用程序时转换为.Config的元素,并且是(据我所知)不受漫游复杂性的影响我知道有两种方法可以进行开箱即用的配置:“设置”您描述的是通过Properties.Settings.Default访问的,而我目前没有使用它(跟踪实际的配置文件,并且必须调用Properties.Settings.Default.Upgrade()让我头疼!);另一种方法是创建一个App.Config,其中包含通过ConfigurationManager.AppSettings编译和访问应用程序时转换为.Config的元素,并且(据我所知)不受漫游限制