简体   繁体   English

调用未知设置

[英]Calling unknown settings

C# Project in Visual Studio 2013 Visual Studio 2013中的C#项目

I need to build a X-Walk (cross reference) between a database's field names and a list of 'Standard' names. 我需要在数据库的字段名称和“标准”名称列表之间建立X-Walk(交叉引用)。

Because this list needs to be maintained and occasionally updated, my inclination is to create a Settings class and then call the setting to get the cross reference. 由于此列表需要维护并偶尔更新,因此我倾向于创建一个Settings类,然后调用该设置以获取交叉引用。 eg 例如

[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("SIZE")]
public string MySize {
    get {
        return ((string)(this["MySize"]));
    }
}

and then it would obviously be called thus: 然后显然可以这样称呼它:

private string str = MyProject.AttributeXref.Default.MySize;

Here is where the rub comes... at run-time the code I have to respond to will be passing the 'Attributes' by name and I have to perform the lookup. 这就是问题所在了……在运行时,我必须响应的代码将按名称传递“属性”,并且我必须执行查找。 If all I have is 'MySize' and not MyProject.AttributeXref.Default.MySize; 如果我只有'MySize'而不是MyProject.AttributeXref.Default.MySize;

should I be doing something similar to MyProject.AttributeXref.{0} 我应该做类似于MyProject.AttributeXref.{0}事情吗

Or... Am I going about this all wrong? 还是...我要把这全部弄错了吗?

and the answer is... 答案是...

var a = "MySize";
var b = MyProject.AttributeXref[a];
Console.WriteLine("MySize = " + b);

Output - MySize = SIZE 输出-MySize = SIZE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM