在一个程序集中使用多个同名类 (DotRas)
本文关键字:DotRas 程序集 一个 程序 集中 | 更新日期: 2023-09-27 17:56:56
我在程序集中使用 DotRas 时遇到问题。其中是每个平台的多个版本的DotRas(WinXP,7,8等)。问题是所有库都具有相同的类和命名空间名称。因此,如果我添加对所有这些的引用并尝试使用它们,VS 会说例如Ambiguous reference: DotRas.RasPhoneBook
那么,是否有可能在一次装配中解决问题呢?或者我只需要为每个 DotRas 类创建包装组装。
您是否尝试为不同的平台(WinXP、7、8 等)使用别名?在使用语句中。它应该可以解决您的问题。
using colAlias = System.Collections;
namespace System
{
class TestClass
{
static void Main()
{
// Searching the alias:
colAlias::Hashtable test = new colAlias::Hashtable();
// Add items to the table.
test.Add("A", "1");
test.Add("B", "2");
test.Add("C", "3");
foreach (string name in test.Keys)
{
// Searching the global namespace:
global::System.Console.WriteLine(name + " " + test[name]);
}
}
}}
完整的示例如下: http://msdn.microsoft.com/en-us/library/c3ay4x3d.aspx
还有用于使用命名空间的 MS 链接:http://msdn.microsoft.com/en-us/library/dfb3cx8s.aspx