c# - Traverse .config file in exe or web app -


i'm writing library used in desktop , web apps. needs traverse section groups in .config file. assume i'll need instance of system.configuration.configuration this. there way works in desktop , web apps?

i ended this:

static configuration openconfiguration() {     if (httpcontext.current != null)         return webconfigurationmanager.openwebconfiguration(null);     return configurationmanager.openexeconfiguration(configurationuserlevel.none); }  static ienumerable<configurationsectiongroup> getconfigsectiongroups() {     var config = openconfiguration();     var stack = new stack<configurationsectiongroup>();     stack.push(config.rootsectiongroup);     while (stack.count > 0) {         var group = stack.pop();         yield return group;         foreach (configurationsectiongroup subgroup in group.sectiongroups) {             stack.push(subgroup);         }     } } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -