I'm taking over a C# project and I have come across a concept that I'm unfamiliar with.
The project is using EF to create look-up tables from enums. The UI is accepting a multi-select input but the receiving model accepts a enum type, not a list/array or something else that would suggest plural.
The enum seems to have some recursive relationship
public enum Options
{
None = 0,
[Display(Name = @"On-site Security")]
OnSiteSecurity = 1 << 0,
[Display(Name = @"Gated Entry")]
GatedEntry = OnSiteSecurity << 1,
[Display(Name = @"Gated Entry - Video")]
GatedEntryVideo = GatedEntry << 1,
[Display(Name = @"Closed-Circuit TV")]
CCTV = GatedEntryVideo << 1, ...
the look-up table has a Value column that with value that grow exponentially, 0,1,2,4,8,16,32,64,128,256,512
and finally the UI has a multi-select input where the value is the same number sequence as the look-up table. There is a sanitation function acting on the value like this (knockout.js)
self.Value = ko.computed({
read: function () {
var value = 0;
$.each(self.Selected(), function (idxitem, item) {
value |= item;
});
return value;
},
write: function (value) {
$.each(self.Available(), function (idxitem, item) {
if ((value & item.Value) > 0) {
item.IsSelected(true);
}
});
self.Normalize(value);
},
owner: self
});
I do not understand how this is supposed to accept plural selections.