Visual Studio 8 中程序集引用的别名属性有什么用 [英] What use is the Aliases property of assembly references in Visual Studio 8

查看:32
本文介绍了Visual Studio 8 中程序集引用的别名属性有什么用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Visual Studio 8 中添加对项目的程序集引用时,该引用的别名属性设置为全局".此属性有什么用处?为什么将其设置为全局?

When I add an assembly reference to a project in Visual Studio 8 the Aliases property, of that reference, is set to "global". What is this property good for and why is it set to global?

MSDN 告诉我这是程序集的别名列表,但不是为什么我可能想要使用此属性或为什么大多数别名为全局".

MSDN tells me that this is a list of aliases for the assembly but not why I might want to use this property or why most are aliased as "global".

MSDN 参考

推荐答案

这是针对外部别名"的.假设您要使用两种不同的类型,它们都称为 Foo.Bar(即 Foo 命名空间中的 Bar).这两种类型将在不同的程序集中(根据定义)-您使用 VS 中的属性将别名与每个引用关联,然后您可以这样做:

This is for "extern aliases". Suppose you want to use two different types, both of which are called Foo.Bar (i.e. Bar in a namespace of Foo). The two types will be in different assemblies (by definition) - you use the property in VS to associate an alias with each reference, then you can do:

extern alias FirstAlias;
extern alias SecondAlias;

using FirstBar = FirstAlias::Foo.Bar;
using SecondBar = SecondAlias::Foo.Bar;

然后在您的代码中使用 FirstBarSecondBar.

and then use FirstBar and SecondBar in your code.

所以基本上它是一个额外的命名级别 - 除非你真的,真的必须使用它,否则你不应该使用它.会迷惑很多人.首先尽量避免陷入这种情况 - 但在无法避免的情况下,请注意此解决方案.

So basically it's an extra level of naming - and you shouldn't use it unless you really, really have to. It will confuse a lot of people. Try to avoid getting into that situation in the first place - but be aware of this solution for those times where you just can't avoid it.

这篇关于Visual Studio 8 中程序集引用的别名属性有什么用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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