TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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(Co
nfigurationManager
.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(Co
nfigurationManager
.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.
Reply
Answers (
1
)
How to Bind the data column from the table into datagridviewcombobox column in c# windows for application.
From Excel Convert into sqlserver database