using System;
namespace JiShe.CollectBus.Common.Extensions
{
public static class EnumExtensions
{
///
/// 将枚举转换为字典
///
///
///
public static Dictionary ToDictionary() where TEnum : Enum
{
return Enum.GetValues(typeof(TEnum))
.Cast()
.ToDictionary(
e => e.ToString(),
e => Convert.ToInt32(e)
);
}
///
/// 将枚举转换为字典
///
///
///
public static Dictionary ToEnumDictionary() where TEnum : Enum
{
return Enum.GetValues(typeof(TEnum))
.Cast()
.ToDictionary(
e => e.ToString(),
e => e
);
}
///
/// 将枚举转换为字典
///
///
///
public static Dictionary ToValueNameDictionary() where TEnum : Enum
{
return Enum.GetValues(typeof(TEnum))
.Cast()
.ToDictionary(
e => Convert.ToInt32(e),
e => e.ToString()
);
}
///
/// 将枚举转换为字典
///
///
///
public static Dictionary ToEnumNameDictionary() where TEnum : Enum
{
return Enum.GetValues(typeof(TEnum))
.Cast()
.ToDictionary(
e => e,
e => e.ToString()
);
}
}
}