I have the following enumerator defined:
[Flags]
public enum CoinSizes
{
[Display(Name = "0.01")]
OneCent = 0x1,
[Display(Name = "0.02")]
TwoCent = 0x2,
[Display(Name = "0.05")]
FiveCent = 0x4,
[Display(Name = "0.10")]
TenCent = 0x8,
[Display(Name = "0.20")]
TwentyCent = 0x16,
[Display(Name = "0.25")]
TwentyFiveCent = 0x32,
[Display(Name = "0.50")]
FiftyCent = 0x64,
[Display(Name = "1.00")]
OneDollar = 0x128,
[Display(Name = "2.00")]
TowDollar = 0x256,
[Display(Name = "5.00")]
FiveDollar = 0x512,
[Display(Name = "10.00")]
TenDollar = 0x1024,
[Display(Name = "25.00")]
TwentyFiveDollar = 0x2048,
[Display(Name = "50.00")]
FiftyDollar = 0x4096
}
I'm building an MVC web app and I have a custom EnumCheckboxListFor helper defined. In the helper, I iterate over the Enum items with Linq and check which ones are selected and therefor which checkboxes need to be checked.
I'm using the following to get the full list of enumerations available, which are then iterated over:
Enum.GetValues((typeof(TEnum)))
LINQ:
TEnum enumValues = expression.Compile()((TModel)htmlHelper.ViewContext.ViewData.Model);
IEnumerable<SelectListItem> items = Enum
.GetValues(enumType)
.Cast<Enum>()
.Select(c => new SelectListItem
{
Text = c.EnumDisplayName().ToString(),
Value = c.ToString(),
Selected = enumValues != null && (value.Equals(c) || value.ToString().Contains(c.ToString()))
}).ToList();
I know the logic to determine "Selected" isn't perfect, but that's a WIP. Mainly, the array that Enum.GetValues() returns is odd:
Enum.GetValues((typeof(TEnum)))
{Href.DataStore.Gambling.Core.CoinSizes[13]}
[0]: OneCent
[1]: TwoCent
[2]: FiveCent
[3]: TenCent
[4]: 22
[5]: 50
[6]: 100
[7]: 296
[8]: 598
[9]: 1298
[10]: 4132
[11]: 8264
[12]: 16534
The first four are correct, but obviously those int values (from index 4 onward) don't correspond to the enumerations' values.
Any ideas why I'd be getting those odd values?