How to distinguish between two classes with the sa

2019-05-21 15:24发布

问题:

I've got two DLL's - a Common.dll and a CFW.Infrastructure.Sdk.dll. Both DLL's contain the following class:

CFW.Common.Hashing.BlockHasher

I have a test project that references both DLL's. When I try to test the BlockHasher, I get the following error:

I like to test the one in the CFW.Infrastructure.Sdk.dll. Because the fully qualified names are the same I can't fix this with a 'normal' using.

回答1:

External aliasses can be used.

1. Add an alias to the DLL reference

Open the solution explorer. Navigate to the DLL and add an alias to it.

2. Reference the alias

Add the following the the C# file (must be on top):

extern alias Sdk;

3.Add some usings to distinguish:

I've added the classes that gave problems as usings:

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

4.Done!

Got the idea from the Extern Alias Walkthrough.