C# 与 Java 不同,枚举只能从数字类型(char、byte、long、int)继承。如果你想要更复杂的东西,我建议使用一个“重”类和一个枚举,如下所示:
public enum MyThingSimple : int {
Enum1 = 0,
Enum2 = 1
}
public sealed class MyThingComplex {
public string Name { get; private set; }
public bool IsMultiColoured { get; private set; }
public bool IsExpensive { get; set; }
public MyThingSimple Value { get; private set; }
public static readonly MyThingComplex Enum1 = new MyThingComplex {
IsExpensive = false,
IsMultiColoured = true,
Value = MyThingSimple.Enum1,
Name = "Enum1"
};
public static readonly MyThingComplex Enum2 = new MyThingComplex {
IsExpensive = false,
IsMultiColoured = true,
Value = MyThingSimple.Enum2,
Name = "Enum2"
};
private static readonly Dictionary<MyThingSimple, MyThingComplex> m_Mapping =
new Dictionary<MyThingSimple,MyThingComplex> {
{ MyThingSimple.Enum1, Enum1 },
{ MyThingSimple.Enum2, Enum2 }
};
public static MyThingComplex FromSimple(MyThingSimple simpleThing) {
return m_Mapping[simpleThing];
}
}