using clause with a "variable" assembly

K

Kevin Frey

Is it possible to get c# perform a using statement where the namespace for
the using is not specified literally but instead comes from a variable, a
token, a predefined value etc.

We have numerous auto-generated assemblies that represent specific database
models within a database, but each assembly uses commonly-named base classes
with common implementations. I am writing code that deals only with the base
classes, hence it *could* be usable with any of these assemblies, but I need
a specific "using" directive to nominate a particular namespace in order to
access the base classes.

However, because our auto-generated assemblies are intended for customer
deployment, we have not tried to "break out" the base classes into a common
assembly or even a common namespace, because if the customer ever needs to
use two of our assemblies simultaneously, there might be two different
versions of the base classes involved (depending on the relative ages of the
assemblies).
 
N

Nicholas Paldino [.NET/C# MVP]

Kevin,

I think it would be a good idea if you separated out the base class and
then had your auto-generated classes derive from that.

You can not use a variable in a using statement. As it stands, without
the common base class, you have to use the full namespace qualified name, or
use the specific namespace declared in your assembly.

Hope this helps.
 
K

Kevin Frey

So let's say I have assembly X using "base class" assembly B1, and assembly
Y using "base class" assembly B2, and B1 and B2 represent [potentially]
different generations of my base classes but have the *same* namespace,
could I actually use X and Y assemblies simultaneously within my program?

How would the compiler treat two assemblies (B1, B2) with an equivalently
named set of base classes named within the same namespace?

Thanks

Kevin

Nicholas Paldino said:
Kevin,

I think it would be a good idea if you separated out the base class and
then had your auto-generated classes derive from that.

You can not use a variable in a using statement. As it stands, without
the common base class, you have to use the full namespace qualified name,
or use the specific namespace declared in your assembly.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Kevin Frey said:
Is it possible to get c# perform a using statement where the namespace
for the using is not specified literally but instead comes from a
variable, a token, a predefined value etc.

We have numerous auto-generated assemblies that represent specific
database models within a database, but each assembly uses commonly-named
base classes with common implementations. I am writing code that deals
only with the base classes, hence it *could* be usable with any of these
assemblies, but I need a specific "using" directive to nominate a
particular namespace in order to access the base classes.

However, because our auto-generated assemblies are intended for customer
deployment, we have not tried to "break out" the base classes into a
common assembly or even a common namespace, because if the customer ever
needs to use two of our assemblies simultaneously, there might be two
different versions of the base classes involved (depending on the
relative ages of the assemblies).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top