G
Guest
I have a class called myConfigurationClass with 3 private members, and 3 public gets (so, 3 read-only properties). So, for instance
private members: _A, _B, _
public gets A, B,
Oh, and they are all strings. In particular, they are Connection strings for SQL Server
In my web config, I have an appSetting, let's call it "CurrentConnectionString", and its value is either "A", "B", or "C
How can you write code so that it reads the value of "CurrentConnectionString" and then executes the proper get
The typical way would be something like
Step 1) create a string to hold the value of the key
Step 2) using either case or if-else if-else, loop through and see what the value is, and do other stuff accordingl
Thus
System.Configuration.AppSettingsReader AppSettingsReader = new System.Configuration.AppSettingsReader()
string ConnectionStringType = (string)AppSettingsReader.GetValue("CurrentConnectionString", typeof(string))
string ConnectionString = ""
if (ConnectionString == "A"
ConnectionString = myConfigurationClass.A
else if (ConnectionString == "B"
ConnectionString = myConfigurationClass.B
els
ConnectionString = myConfigurationClass.
Is there a way that I could dump the if - else stuff and write something like
string ConnectionString = myConfigurationClass.[ConnectionStringType]; //which doesn't wor
where it 'dynamically' writes the code that follows "myConfigurationClass.
TI
jdn
private members: _A, _B, _
public gets A, B,
Oh, and they are all strings. In particular, they are Connection strings for SQL Server
In my web config, I have an appSetting, let's call it "CurrentConnectionString", and its value is either "A", "B", or "C
How can you write code so that it reads the value of "CurrentConnectionString" and then executes the proper get
The typical way would be something like
Step 1) create a string to hold the value of the key
Step 2) using either case or if-else if-else, loop through and see what the value is, and do other stuff accordingl
Thus
System.Configuration.AppSettingsReader AppSettingsReader = new System.Configuration.AppSettingsReader()
string ConnectionStringType = (string)AppSettingsReader.GetValue("CurrentConnectionString", typeof(string))
string ConnectionString = ""
if (ConnectionString == "A"
ConnectionString = myConfigurationClass.A
else if (ConnectionString == "B"
ConnectionString = myConfigurationClass.B
els
ConnectionString = myConfigurationClass.
Is there a way that I could dump the if - else stuff and write something like
string ConnectionString = myConfigurationClass.[ConnectionStringType]; //which doesn't wor
where it 'dynamically' writes the code that follows "myConfigurationClass.
TI
jdn