views:

97

answers:

2

Since I am using two different generic collection namespaces (System.Collections.Generic and Iesi.Collections.Generic), I have conflicts. In other parts of the project, I am using both the nunit and mstest framework, but qualify that when I call Assert I want to use the nunit version by

using Assert = NUnit.Framework.Assert;

Which works great, but I want to do the same thing with generic types. However, the following lines do not work

using ISet = System.Collections.Generic.ISet;
using ISet<> = System.Collections.Generic.ISet<>;

Does anyone know how to tell .net how to use the using statement with generics?

Thanks!

+8  A: 

I think you're better off aliasing the namespaces themselves as opposed to the generic types (which I don't think is possible).

So for instance:

using S = System.Collections.Generic;
using I = Iesi.Collections.Generic;

Then for a BCL ISet<int>, for example:

S.ISet<int> integers = new S.HashSet<int>();
Dan Tao
+4  A: 

The only way you can alias a generic type is to specialize it as follows.

using IntSet = System.Collections.Generic.ISet<int>;

You can not alias an open generic type as you have done in your example:

using MySet = System.Collections.Generic.ISet<>;
Steve Guidi
Thanks Steve, I will be able to use this later!
Jason More