using System;
using System.Collections.Generic;
using System.Linq;
namespace ACE.Common.Extensions
{
public static class EnumHelper
{
///
/// Returns a list of flags for enum
///
public static List GetFlags(this Enum e)
{
return Enum.GetValues(e.GetType()).Cast().Where(e.HasFlag).ToList();
}
///
/// Returns the # of bits set in a Flags enum
///
/// The enum uint value
public static int NumFlags(uint enumVal)
{
var cnt = 0;
while (enumVal != 0)
{
// remove the next set bit
enumVal &= enumVal - 1;
cnt++;
}
return cnt;
}
///
/// Returns TRUE if this flags enum has multiple flags set
///
/// The enum uint value
public static bool HasMultiple(uint enumVal)
{
return (enumVal & (enumVal - 1)) != 0;
}
}
}