c# - Is there a way to get a System.Configuration.Configuration instance based on arbitrary xml? -


i'm trying unit test custom configurationsection i've written, , i'd load arbitrary configuration xml system.configuration.configuration each test (rather put test configuration xml in tests.dll.config file. is, i'd this:

configuration testconfig = new configuration("<?xml version=\"1.0\"?><configuration>...</configuration>"); mycustomconfigsection section = testconfig.getsection("mycustomconfigsection"); assert.that(section != null); 

however, looks configurationmanager give configuration instances associated exe file or machine config. there way load arbitrary xml configuration instance?

there way i've discovered....

you need define new class inheriting original configuration section follows:

public class myxmlcustomconfigsection : mycustomconfigsection {     public myxmlcustomconfigsection (string configxml)     {         xmltextreader reader = new xmltextreader(new stringreader(configxml));         deserializesection(reader);     } } 


can instantiate configurationsection object follows:

string configxml = "<?xml version=\"1.0\"?><configuration>...</configuration>"; mycustomconfigsection config = new myxmlcustomconfigsection(configxml); 

hope helps :-)


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -