英文:
how to solve ambiguous reference between two namespaces in .NET
问题
我在Unity中使用.NET Framework进行开发。
我经常使用 List<string>
。突然,今天我收到消息说 zenject.List<t>
和 System.Collections.Generic.List<t>
之间存在歧义。
当我点击 "yes" 时,它将所有 List<string>
实例更改为 System.Collections.Generic.List<string>
。
我不想使用Zenject的列表。我宁愿不每次需要列表时都写完整的 System.Collections.Generic.List<string>
。
是否有配置所有 List<string>
默认关联到泛型命名空间的选项?
我尝试写:
using List = System.Collections.Generic;
但它没有解决问题。
英文:
I'm developing in Unity with the .NET Framework.
I'm using List<string>
a lot. Suddenly, today I got message that there is ambiguous between zenject.List<t>
and System.Collections.Generic.List<t>
.
When I clicked "yes", it changed all List<string>
instances to System.Collections.Generic.List<string>
.
I don't want to use list of Zenject at all. And I prefer not to write the full System.Collections.Generic.List<string>
every time I need a list.
Is there an option to configure that all List<string>
will be related to the generic namespace by default?
I tried to write
using List = System.Collections.Generic;
but it didn't solve the issue.
答案1
得分: 1
Your using alias misses a type in its declaration:
使用别名缺少类型声明:
using GenericListOfStrings = System.Collections.Generic.List<string>;
使用 GenericListOfStrings = System.Collections.Generic.List<string>;
I am not familiar with Zenject, but the better approach IMO would be to encapsulate all usages of Zenject in a class, so you don't need that namespace in your source code:
我不熟悉Zenject,但在我看来,更好的方法是将Zenject的所有用法封装在一个类中,这样你的源代码中就不需要这个命名空间:
For example:
例如:
using Zenject;
namespace Zenject // imagine this code in a third party library
{
class SomeZenjectClass { }
}
namespace YourCode
{
class ZenjectContainer
{
public void SomeMethod()
{
var obj = new SomeZenjectClass();
}
}
}
Then your code can exclude conflicting namespace:
然后你的代码可以排除冲突的命名空间:
using YourCode;
var zenject = new ZenjectContainer();
var list = new List<string>(); // I can use lists!
var zenject = new ZenjectContainer();
var list = new List<string>(); //我可以使用列表!
英文:
Your using alias misses a type in its declaration
using GenericListOfStrings = System.Collections.Generic.List<string>;
var strings = new GenericListOfStrings();
I am not familiar with Zenject, but the better approach IMO would be to encapsulate all usages of Zenject in a class, so you don't need that namespace in your source code
For example,
using Zenject;
namespace Zenject // imagine this code in a third party library
{
class SomeZenjectClass { }
}
namespace YourCode
{
class ZenjectContainer
{
public void SomeMethod()
{
var obj = new SomeZenjectClass();
}
}
}
Then your code can exclude conflicting namespace
using YourCode;
var zenject = new ZenjectContainer();
var list = new List<string>(); // I can use lists!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论