public enum SampleEnum
{
[Description("東京")]
Tokyo = 1,
[Description("名古屋")]
Nagoya = 3,
[Description("札幌")]
Sapporo = 5,
[Description("大阪")]
Osaka = 7
}
static void Test2()
{
Console.WriteLine("EnumExtention GetDescriptionFromValueを使ってTokyoのDescriptionを取得");
Console.WriteLine(SampleEnum.Tokyo.GetDescriptionFromValue());
Console.WriteLine();
Console.WriteLine("StringExtention GetEnumValueFromDescriptionを使ってDescriptionからenum値を取得");
Console.WriteLine("名古屋".GetEnumValueFromDescription<SampleEnum>());
Console.WriteLine();
Console.WriteLine("IntExtention GetEnumDescriptionFromIntを使ってint値からDescriptionを取得");
var sapporo = ((int)5).GetEnumDescriptionFromInt<SampleEnum>();
Console.WriteLine(sapporo);
Console.WriteLine();
Console.WriteLine("IntExtention GetEnumValueFromIntを使ってint値からenum値を取得");
var osaka = ((int)7).GetEnumValueFromInt<SampleEnum>();
Console.WriteLine(osaka);
Console.WriteLine();
Console.WriteLine("TypeExtention GetEnumListを使ってenumの値リストを取得");
var enumValues = typeof(SampleEnum).GetEnumList<SampleEnum>();
foreach (var e in enumValues)
Console.WriteLine(e);
Console.WriteLine();
Console.WriteLine("TypeExtention GetEnumDescriptionListを使ってDescriptionリストを取得");
var enumDescriptions = typeof(SampleEnum).GetEnumDescriptionList<SampleEnum>();
foreach (var e in enumDescriptions)
Console.WriteLine(e);
Console.WriteLine();
Console.WriteLine("TypeExtention GetEnumDescriptionEnumerableを使ってDescriptionリストを取得");
var enumDescriptionsEnumerable = typeof(SampleEnum).GetEnumDescriptionEnumerable<SampleEnum>();
foreach (var e in enumDescriptionsEnumerable)
Console.WriteLine(e);
Console.ReadLine();
}