I want to reuse some code logic from a self-hosted web application in my Windows Azure web application. Currently I have code like this:
void myFunction( params )
{
//environment-neutral code
}
I need to rewrite that code to make the program act differently depending on whether is is on Azure:
void myFunctionModified( params )
{
if( onAzure() ) {
//run Azure-specific code
} else {
//run non-Azure code
}
}
yes, I know about virtual functions, but I'll need such code for at least instantiating the right object before I can call those virtual functions.
The problem is to implement onAzure()
I need to use stuff from an assembly that is only present on Windows Azure (like RoleEnvironment
for example). So I don't see how I can implement onAzure()
so that it doesn't crash when run outside Windows Azure environment.
How do I make my application act differently depending on what assemblies are present on the system?