如何区分2个DLL中具有相同名称(和命名空间)的两个类?

时间:2016-07-28 09:34:00

标签: c# .net dll namespaces

我有两个DLL - Common.dllCFW.Infrastructure.Sdk.dll。这两个DLL都包含以下类:

CFW.Common.Hashing.BlockHasher

我有一个测试项目,它引用了两个DLL。当我尝试测试BlockHasher时,我收到以下错误:

Blockhasher exists in both DLL's

我喜欢测试CFW.Infrastructure.Sdk.dll中的那个。因为完全限定的名称是相同的,所以我无法通过“正常”使用来解决这个问题。

1 个答案:

答案 0 :(得分:2)

External aliasses可以使用。

1。为DLL引用添加别名

打开解决方案资源管理器。导航到DLL并向其添加alias

Properties of the reference

2。引用别名

在C#文件中添加以下内容(必须在顶部):

extern alias Sdk;

3.添加一些usings来区分:

我添加了使用的问题类:

using BlockHasher = Sdk.CFW.Common.Hashing.BlockHasher; 
using SigningAlgorithm = Sdk.CFW.Common.Hashing.SigningAlgorithm;

4.Done!

Extern Alias Walkthrough获得了这个想法。