简体   繁体   中英

Whats a good way to switch between two “using” statements in a compiled library?

I'm sectioning off pieces of a solutions into individual solutions and integrating them into an Atlassian Bamboo build/deploy environment. I have a site, a WCF with Windows Workflow Foundation, and a library containing all the classes that are shared. All is written in C# btw.

One thing inside the library is a class that interfaces with a Magento (php based) SOAP interface. Basically it just provides me with a handler for all of the SOAP Exceptions that Magento spits back to me. It uses SOAP Exceptions as valid, but bad results... Example "Product X does not exist". etc.

It could be ANY SOAP interface though. MEAT AND POTATOS:

I have a development and production Magento machine, and I have two pretty much identical soap interfaces.. www.mysite.com/soap/etc and dev.mysite.com/soap/etc exposed by these two machines. Each is loaded as a web reference in the library, and for a long time I was using a compile time #if DEBUG constant to switch between two different "Using" statements. Whether I picked debug or release, it would choose the correct reference. Here is the code:

#if DEBUG
    using NKI.Library.MagentoDev;
#else
    using NKI.Library.MagentoProd;
#endif

Now, I need to be able to specify this 'pick' later, after the library has been compiled into a DLL.. (btw, don't get on my case about hard coding a url into the dll :)

The preprocessor is obviously a compile-time directive as is using . You can't change what using does after compilation for obvious reasons.

That said, if both MagentoDev and MagentoProd derive from the same common base-class, then there's nothing stopping you have a configuration file where a setting is read in and the code uses the appropriate interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM