using DominionBase.Enums; using System; using System.ComponentModel; using System.Diagnostics.Contracts; namespace DominionBase.Enums { public static class EnumUtility { public static string GetEnumDescription(Enum value) { Contract.Requires(value != null, "value cannot be null"); var fi = value.GetType().GetField(value.ToString()); var attributes = (DescriptionAttribute[])fi.GetCustomAttributes( typeof(DescriptionAttribute), false); return attributes.Length > 0 ? attributes[0].Description : value.ToString(); } internal static UInt32 Count(this Categories category) { var v = (UInt32)category; v = v - ((v >> 1) & 0x55555555); // reuse input as temporary v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp var c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count return c; } } }