I have to cast enum but I want this to be as generic as possbile. How can I replace the Cast<XX>()
part with propertyType
?
foreach (var prop in MainType.GetProperties().Where(x => x.PropertyType.IsEnum))
{
var x = new { name = prop.Name, values = new List<object>() };
foreach (var v in Enum.GetValues(prop.PropertyType).Cast<XX>())
x.values.Add(new { p = v.GetAttribute<DescriptionAttribute>().Description, c = v.GetAttribute<DefaultValueAttribute>().Value });
o.Add(x);
}
Aucun commentaire:
Enregistrer un commentaire