C# extern alias
I have two assemblies with the exact same interface (lets call them Assem1 and Assem2)
Is it possible to use extern alias in order to call methods of Assem1 from Assem2?
The source code is something like this:
//Pre steps - set Reference in Assem1 to assem2 and set it's alias to Assem2Alias
//Both assemblies named MyAssembly.dll, has exact same interface but different Guids
//Assem1 code
extern alias Assem2;
using Assem2 = Assem2Alias.MyAssembly;
namespace MyAssembly
{
public class MyClass
{
public int Foo()
{
开发者_StackOverflow中文版 return new Assem2.MyClass().Foo();
}
}
}
//Assem2 code
namespace MyAssembly
{
public class MyClass
{
public int Foo()
{
return 10;
}
}
}
Edited: As requested - I'm adding extra information regard the general task:
I need to test application that uses ActiveX.exe to get data (responses) from external services. My task is to replace this ActiveX.exe so I will control the responses. Since the responses are large textual data, I would to generate the request using the original ActiveX.exe file.
The new assembly (Assem1 in my question) must have the exact same interface as the original ActiveX.exe (Assem2). The general idea: Assem1 gets a request from the tested application. If the request matches response in its data source --> it read the response and return it to the application. If it does not match any of the responses, then Assem1 requests Assem2 for response, adds it to its data source and response to the tested application.
As mentioned both must have the exact same interface, so I uses extern alias to refer to the original ActiveX.exe. All the examples on the internet using extern alias in C# specified to one assembly refering to two assemblies with the same interface, but not from one to each other.
精彩评论