Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 04, 2011 01:31 PM by ramjet69
Nov 03, 2011 06:23 PM|LINK
I am trying to eliminate if not ALL as many hardcodes as possible in our coding practices. I have eliminated about 70% just by moving to constants so at least they are centrally located. I then moved to populating the constants from the Web Config in the
appSettings section. I then came up with this design which I now present for critical review.
I created a static class called SessionConstants and in the constructor I loop through appSettings for all the keys and values. I then try to assign the property the value from the NameValueCollection using the Get method....but the Get method requires a
string...so I'm back to having a hard code. What I was thinking would be cool is if I could use the properties name as the string value to be matched in the NameValue collection. So if my property had the exact same name as the web config appSetting key then
a property could be populated by it's matching entry in the web config.
If this is possible I would appreciate knowing how to get the propertyName to be used as the string value for the get method of the NameValueCollection. If this is a bad idea let fly on why. Unlike 90% of society I won't be offended....I will be grateful.
Nov 03, 2011 08:42 PM|LINK
You really don't need a static class. Web.Config is cached.
Nov 04, 2011 06:54 AM|LINK
What I was thinking would be cool is if I could use the properties name as the string value to be matched in the NameValue collection. So if my property had the exact same name as the web config appSetting key then a property could be populated by it's matching
entry in the web config
Why not use a configSection instead? There you create the class you need to hold your configuration settings and have that class load its setting from its configSection in you config file.
Nov 04, 2011 10:02 AM|LINK
That's cool to know. I thought it was a disk I/O to read the web config.
Nov 04, 2011 01:31 PM|LINK
I just read this.