I have some code that references an outside DLL which in production will be loaded by a factory. The DLL shouldn't be referenced directly by my assembly, it will be loaded at runtime using Assembly.Load().
This all works just fine, but when it comes to debugging, I want to be able to step through the library as if I'd referenced it using something like new MyConcreteObject()
.
I know that I can use #if #endif to compile code differently in debug/release - but can I also have a reference that is only attached in debug/release?
If I can, and that is how I should do this, how do I go about it? If not, how should I be going about this?
Currently I have:
public class ObjectFactory
{
public IObject CreateObject(string objectType)
{
/* Code to load and return the concrete object specified in the app.config */
}
}
public class Program
{
public void Main(string[] args)
{
IObject obj = ObjectFactory.CreateObject("MyObject, MyObjectLibrary");
obj.DoYourStuff();
}
}
So now I want to step through the code for the "DoYourStuff()" method and I don't want to have to comment out the line that loads my object and replace it with:
IObject obj = new MyObject();
Which then requires a project reference pointing to the MyObjectLibrary DLL that will require I remove the reference and uncomment out the CreateObject() call and instead comment out the line that new's up the concrete object.
Make sense?