.NET - 具有相同命名空间的多个库 - 引用 [英] .NET - Multiple libraries with the same namespace - referencing

查看:24
本文介绍了.NET - 具有相同命名空间的多个库 - 引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我面临着一个奇怪的挑战......

这个挑战涉及我需要从我的应用程序中引用的两个 .NET 库.两者我都无法控制,并且在它们中具有相同的命名空间.

所以...

我的 foo.dll 包含一个 Widget 类,该类位于 Blue.Red.Orange 命名空间中.

我的 bar.dll 还包含一个 Widget 类,该类也位于 Blue.Red.Orange 命名空间中.p>

最后,我的应用程序需要同时引用 foo.dllbar.dll.这是需要的,因为在我的应用程序中,我需要使用 foo 中的 Widget 类以及 bar 中的 Widget 类>

那么,问题是如何管理这些引用,以便确定我使用的是正确的 Widget 类?

如前所述,我无法控制 foobar 库,它们就是它们的本来面目,无法更改.但是,我可以完全控制我的应用程序.

解决方案

您需要使用 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 - 具有相同命名空间的多个库 - 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆