Calling unknown settings

70 views Asked by At

C# Project in Visual Studio 2013

I need to build a X-Walk (cross reference) between a database's field names and a list of 'Standard' names.

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. e.g.

[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;

should I be doing something similar to MyProject.AttributeXref.{0}

Or... Am I going about this all wrong?

1

There are 1 answers

0
ConcordCA On

and the answer is...

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

Output - MySize = SIZE