I want to implement an extension method which converts an enum to a dictionary:
public static Dictionary<int, string> ToDictionary(this Enum @enum)
{
Type type1 = @enum.GetType();
return Enum.GetValues(type1).Cast<type1>()
//.OfType<typeof(@enum)>()
.ToDictionary(e => Enum.GetName(@enum.GetType(), e));
}
Why it doesn't compile?
An error:
"The type or namespace name 'type1'
could not be found (are you missing a
using directive or an assembly
reference?)"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…