Search code examples
c#genericssyntaxaliasusing

Using Statement with Generics: using ISet<> = System.Collections.Generic.ISet<>


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?


Solution

  • 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>();