别名在.NET别名、NET

由网友(我命由我不由天)分享简介:是否有可能创建一个别名,以现有的类型和使用的别名,通过了这个项目?Is it possible to create an alias to existing types and use that alias through out the project?例如,创建CustomerID = System.UInt...

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

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:我还没有使用过该功能之前,但转发类型的也许的是有帮助的。它只是转发到另一个整个组件,虽然如此,它可能不会简单的情况下工作。

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.

阅读全文

相关推荐

最新文章