Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aliasing in .NET

Tags:

.net

c#-4.0

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

For example, create

CustomerID = System.UInt32

and use CustomerID as a datatype?

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.)

Any other ideas?

like image 936
fr21 Avatar asked Oct 11 '22 16:10

fr21


1 Answers

I believe the correct answer to this question is:

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


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.


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.

like image 137
user541686 Avatar answered Oct 20 '22 08:10

user541686