diff --git a/src/Umbraco.Core/EnumExtensions.cs b/src/Umbraco.Core/EnumExtensions.cs
index 1443a27876..9097432f64 100644
--- a/src/Umbraco.Core/EnumExtensions.cs
+++ b/src/Umbraco.Core/EnumExtensions.cs
@@ -3,43 +3,42 @@
namespace Umbraco.Core
{
///
- /// Provides extension methods to enums.
+ /// Provides extension methods to .
///
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.
+ /// Determines whether all the flags/bits are set within the enum value.
///
- ///
- /// 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)
+ /// The enum type.
+ /// The enum value.
+ /// The flags.
+ ///
+ /// true if all the flags/bits are set within the enum value; otherwise, false.
+ ///
+ [Obsolete("Use Enum.HasFlag() or bitwise operations (if performance is important) instead.")]
+ public static bool HasFlagAll(this T value, T flags)
where T : Enum
{
- var num = Convert.ToUInt64(use);
- var nums = Convert.ToUInt64(uses);
-
- return (num & nums) == nums;
+ return value.HasFlag(flags);
}
///
- /// Determines whether a flag enum has any of the specified values.
+ /// Determines whether any of the flags/bits are set within the enum value.
///
- ///
- /// True when at least one of the bits set in is set in .
- ///
- public static bool HasFlagAny(this T use, T uses)
+ /// The enum type.
+ /// The value.
+ /// The flags.
+ ///
+ /// true if any of the flags/bits are set within the enum value; otherwise, false.
+ ///
+ public static bool HasFlagAny(this T value, T flags)
where T : Enum
{
- var num = Convert.ToUInt64(use);
- var nums = Convert.ToUInt64(uses);
+ var v = Convert.ToUInt64(value);
+ var f = Convert.ToUInt64(flags);
- return (num & nums) > 0;
+ return (v & f) > 0;
}
}
}
diff --git a/src/Umbraco.Tests/CoreThings/EnumExtensionsTests.cs b/src/Umbraco.Tests/CoreThings/EnumExtensionsTests.cs
index 72a55cee85..faa15b0077 100644
--- a/src/Umbraco.Tests/CoreThings/EnumExtensionsTests.cs
+++ b/src/Umbraco.Tests/CoreThings/EnumExtensionsTests.cs
@@ -1,6 +1,7 @@
-using NUnit.Framework;
-using Umbraco.Web.Trees;
+using System;
+using NUnit.Framework;
using Umbraco.Core;
+using Umbraco.Web.Trees;
namespace Umbraco.Tests.CoreThings
{
@@ -22,6 +23,7 @@ namespace Umbraco.Tests.CoreThings
Assert.IsFalse(value.HasFlag(test));
}
+ [Obsolete]
[TestCase(TreeUse.Dialog, TreeUse.Dialog, true)]
[TestCase(TreeUse.Dialog, TreeUse.Main, false)]
[TestCase(TreeUse.Dialog | TreeUse.Main, TreeUse.Dialog, true)]