.NET - Multiple libraries with the same namespace - referencing(.NET - 具有相同命名空间的多个库 - 引用)
问题描述
今天我面临着一个奇怪的挑战......
这个挑战涉及我需要从我的应用程序中引用的两个 .NET 库.两者我都无法控制,并且在它们中具有相同的命名空间.
所以...
我的 foo.dll 包含一个
Widget
类,该类位于 Blue.Red.Orange
命名空间中.
我的 bar.dll
还包含一个 Widget
类,该类也位于 Blue.Red.Orange
命名空间中.p>
最后,我的应用程序需要同时引用 foo.dll
和 bar.dll
.这是需要的,因为在我的应用程序中,我需要使用 foo
中的 Widget
类以及 bar
中的 Widget
类>
那么,问题是如何管理这些引用,以便确定我使用的是正确的 Widget
类?
如前所述,我无法控制 foo
或 bar
库,它们就是它们的本来面目,无法更改.但是,我可以完全控制我的应用程序.
您需要使用 extern alias - 在 C# 2 中引入.
Anson Horton 在他的博客上有一个演练,您可以觉得有用.
Today I am faced with a curious challenge...
This challenge involves two .NET libraries that I need to reference from my application. Both of which I have no control over and have the same namespace within them.
So...
I have foo.dll
that contains a Widget
class that is located on the Blue.Red.Orange
namespace.
I have bar.dll
that also contains a Widget
class that is also located on the Blue.Red.Orange
namespace.
Finally I have my application that needs to reference both foo.dll
and bar.dll
. This is needed as within my application I need to use the Widget
class from foo
and also the Widget
class from bar
So, the question is how can I manage these references so that I can be certain I am using the correct Widget
class?
As mentioned, I have no control over the foo
or bar
libraries, they are what they are and cannot be changed. I do however have full control over my application.
You need to use an extern alias - introduced in C# 2.
Anson Horton has a walkthrough on his blog which you may find useful.
这篇关于.NET - 具有相同命名空间的多个库 - 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET - 具有相同命名空间的多个库 - 引用


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01