Type Name aliasing in C#

Possible Duplicates:
typedef in C#?
STL like containter typedef shortcut?

I was wondering if there was an equivalent to Type aliasing from Functional Languages that I can use in C#

For example in a nice functional language like Haskell I can say something like the following to alias an existing type to a custom Type Name

type MyCustomTypeName = String

I'd like to do this as I have an API that I'm building where some of the Objects I'm using have multiple possible names in the sense they could be referred to by several terms which are interchangeable and equivalent. Presumably I could do this with inheritance but that seems somewhat clunky and then potentially breaks if people start extending the non-canonical class ie.

public class CanonicalClass {
  //Full Implementation
}

public class AlternateName : CanonicalClass {
 //Empty except I'll need to redefine all the constructors
 //Could declare it sealed but doesn't get rid of the need to redefine constructors
}

And before anyone mentions interfaces all the Classes in question are all implementing interfaces already and there are multiple differing implementations of these interfaces.


根据你实际尝试做什么(给出一个更完整的例子),你可能确实需要接口(正确使用)和/或泛型。

链接地址: http://www.djcxy.com/p/85312.html

上一篇: 浮点类型名称与整型类型名称匹配?

下一篇: 在C#中键入名称别名