Java とは異なり、C# は、数値型 (char、byte、long、int) からのみ継承された列挙型を持つことができます。もっと複雑なものが必要な場合は、次のように 1 つの「重い」クラスと 1 つの列挙型を使用することをお勧めします。
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];
}
}