.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 - 具有相同命名空间的多个库 - 引用


- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01