using System;
namespace Umbraco.Core
{
///
/// Provides extension methods to enums.
///
public static class EnumExtensions
{
// note:
// - no need to HasFlagExact, that's basically an == test
// - HasFlagAll cannot be named HasFlag because ext. methods never take priority over instance methods
///
/// Determines whether a flag enum has all the specified values.
///
///
/// True when all bits set in are set in , though other bits may be set too.
/// This is the behavior of the original method.
///
public static bool HasFlagAll(this T use, T uses)
where T : Enum
{
var num = Convert.ToUInt64(use);
var nums = Convert.ToUInt64(uses);
return (num & nums) == nums;
}
///
/// Determines whether a flag enum has any of the specified values.
///
///
/// True when at least one of the bits set in is set in .
///
public static bool HasFlagAny(this T use, T uses)
where T : Enum
{
var num = Convert.ToUInt64(use);
var nums = Convert.ToUInt64(uses);
return (num & nums) > 0;
}
}
}