使用带有泛型的语句:使用 ISet<>= System.Collections.Generic.ISet<> [英] Using Statement with Generics: using ISet<> = System.Collections.Generic.ISet<>
问题描述
因为我使用了两个不同的通用集合命名空间(System.Collections.Generic
和 Iesi.Collections.Generic
),所以我有冲突.在项目的其他部分,我同时使用 nunit 和 mstest 框架,但是当我调用 Assert
时,我想通过
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<>;
有谁知道如何告诉 .net 如何将 using 语句与泛型结合使用?
Does anyone know how to tell .net how to use the using statement with generics?
推荐答案
我认为你最好给命名空间本身加上别名,而不是泛型类型(我认为这是不可能的).
I think you're better off aliasing the namespaces themselves as opposed to the generic types (which I don't think is possible).
例如:
using S = System.Collections.Generic;
using I = Iesi.Collections.Generic;
然后对于 BCL ISet
,例如:
Then for a BCL ISet<int>
, for example:
S.ISet<int> integers = new S.HashSet<int>();
这篇关于使用带有泛型的语句:使用 ISet<>= System.Collections.Generic.ISet<>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!