user34537
user34537

Reputation:

alias keyword (like typedef) in C#?

I have 2 libs that have different case on different platforms :(. It seems like everything else is the same (method names, param order, etc). How can i create an alias so my current spelling for platform a will work when i compile for platform b (I would really hate to make a wrapper for case difference)

Upvotes: 3

Views: 3344

Answers (2)

itowlson
itowlson

Reputation: 74802

You can use the using keyword to create an alias:

using MyName = YourNamespace.YourSubNamespace.YourType;

You could then conditionally include the aliases using a #if directive. However you would need to do this at the top of every source file: there's no #include-like directive to allow you to create a file of aliases and import them into each source file. So if you are planning on doing this in for a large codebase then it may be worth considering another approach such as the wrapper approach.

Upvotes: 5

JP Alioto
JP Alioto

Reputation: 45117

In C#, you can create an alias for a namespace or a type. It's not quite as flexible as typedef, but it might make it possible for you to alias the type in your lib a to have the lowercase (or uppercase or whatever) like you want to do.

Upvotes: 1

Related Questions