namespaces with the "using" directive

Posted by Ascholfield under C# on 11/18/2009 | Views : 1152 | Status : [Member] | Replies : 2
i have been searching online for a while with this question... all to no avail.

if you are writing a module that modifies existing software then in your module classes you implement some of their code:

using existingSoftware.helperClass;
using existingSoftware.DAL;

namespace MyModule
{
class moduleHelper
{
}
}



if the existing software changes to the point of having a namespace change, is there a way to import the namespace into your module based on if the namespace exists? somthing like this:

using existingSoftware.helperClass;

if(existingSoftware.DAL != null)
using existingSoftware.DAL;

else if(existingSoftware.LinqDAL!= null)
using existingSoftware.LinqDAL;

namespace MyModule
{
class moduleHelper
{
}
}


The point of this question is so that i don't have to maintain two code branches where one imports "existingSoftware.LinqDAL" and the other imports "existingSoftware.DAL". I have already abstracted till it's just one line of code diffrence it's just annoying that it has to be done that way.




Responses

Posted by: Lakhangarg on: 11/19/2009 [Member] [Moderator] Silver

Up
0
Down
Hi-

if both the namespaces are available then you can import both simultaneously. but if only one is available then the above code will give you error at compile time. so not feasible using:

using existingSoftware.helperClass;

if(existingSoftware.DAL != null)
using existingSoftware.DAL;
else if(existingSoftware.LinqDAL!= null)
using existingSoftware.LinqDAL;
namespace MyModule
{
class moduleHelper
{
}
}


Thanks & Regards
Lakhan Pal Garg

Ascholfield, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ascholfield on: 11/19/2009 [Member] Starter

Up
0
Down
yeah thats the thing the existing software moved most of the namespace to "existingSoftware.LinqDAL" and left some functionality in "existingSoftware.DAL" but since the older version doesn't have the newer name-space i am stuck maintaining two branches.

Ascholfield, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response