别名在.NET [英] Aliasing in .NET

查看:132
本文介绍了别名在.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能创建一个别名,以现有的类型和使用的别名,通过了这个项目?

Is it possible to create an alias to existing types and use that alias through out the project?

例如,创建

CustomerID = System.UInt32

和使用CustomerID作为数据类型?

and use CustomerID as a datatype?

版本:.NET框架4.0

Version : .NET Framework 4.0

(与用的关键字,我们将能够创建一个别名,但它是没有用的,因为它不工作在整个文件。)

(With the "using" keyword we would be able to create an alias, but it is not useful as it does not work across files.)

任何其他的想法?

推荐答案

我认为正确的答案,这个问题是:

I believe the correct answer to this question is:

没有,那是(可惜?)是不可能的。 :(

No, that's (unfortunately?) not possible. :(

编辑1:然而的,你的可以的(种)模拟这种通过自己的结构,和提供隐式转换到/从你想要的类型。这不完全是神奇的,但它可能工作,视情况而定。

Edit 1: However, you can (kind of) simulate this by making your own struct, and providing implicit conversions to/from the type you want. It's not exactly magical but it might work, depending on the situation.

编辑2:我还没有使用过该功能之前,但<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.typeforwardedtoattribute.aspx"相对=nofollow>转发类型的也许的是有帮助的。它只是转发到另一个整个组件,虽然如此,它可能不会简单的情况下工作。

Edit 2: I haven't ever used this feature before, but type forwarding might be helpful. It only forwards to another entire assembly, though, so it probably won't work for simple cases.

这篇关于别名在.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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