scampercat

scampercat

  • NA
  • 189
  • 0

app.config file values used with enums

Nov 6 2012 3:09 PM
In a C# 2008 application I am trying to determine how to correlate values from an app.config file with an enum value. 
 Right now in this C# application the user roles are hard-coded and the hardcoded values are used in an enumeration based upon user roles.
The enumeration looks like the following:public enum ERole  {
  User = 0, Manager  = 1,  Administrator = 2, read =3}
switch (eRole)  {
case User: 
return IsInGroup(ConfigurationManager.AppSettings["user"]); 
case Read: 
return IsInGroup(ConfigurationManager.AppSettings["read"]);
default: 
return false;
  }

 Now I am changing the code to use values from the app.config file instead of using hard-coded values.

The app.config file looks like the following:
  < appSettings>
  <add key="role_user" value="CQT123"  />
  <add key="role_Manager" value="CQT1298*"  />
  <add key="role_Administrator" value="ZZ35"  />
  <add key="role_ read" value="cv54"  />
  </appSettings>switch (eRole)  {
case User: 
return IsInGroup(ConfigurationManager.AppSettings["user"]); 
case Read: 
return IsInGroup(ConfigurationManager.AppSettings["read"]);
default: 
return false;
  }

 However my problem is, how should I change the enum listed above so I do not use the hard-coded value for User, Manager, Administrator, and read? I could possibly change the switch statement.

Answers (1)