< Summary

Class:GDX.EnumExtensions
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/EnumExtensions.cs
Covered lines:0
Uncovered lines:14
Coverable lines:14
Total lines:54
Line coverage:0% (0 of 14)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:2
Method coverage:0% (0 of 2)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HasFlags[T](...)0%12300%
HasFlags[T](...)0%2100%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/EnumExtensions.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Runtime.CompilerServices;
 7
 8namespace GDX
 9{
 10    /// <summary>
 11    ///     Enumeration Based Extension Methods
 12    /// </summary>
 13    [VisualScriptingCompatible(2)]
 14    public static class EnumExtensions
 15    {
 16        /// <summary>
 17        ///     Determine if the provide flags (<paramref name="needles" />) are found in the <paramref name="haystack" 
 18        /// </summary>
 19        /// <param name="haystack">A predefined flag based enumeration.</param>
 20        /// <param name="needles">A set of flags to search for in the predefined enumeration.</param>
 21        /// <typeparam name="T">The enumeration's type.</typeparam>
 22        /// <returns>true if the needles are found in the haystack, otherwise false.</returns>
 23        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 24        static unsafe bool HasFlags<T>(T* haystack, T* needles) where T : unmanaged, Enum
 025        {
 026            byte* flags = (byte*)haystack;
 027            byte* query = (byte*)needles;
 28
 029            for (int i = 0; i < sizeof(T); i++)
 030            {
 031                if ((flags[i] & query[i]) != query[i])
 032                {
 033                    return false;
 34                }
 035            }
 36
 037            return true;
 038        }
 39
 40        /// <summary>
 41        ///     Determine if the provide flags (<paramref name="needles" />) are found in the <paramref name="haystack" 
 42        /// </summary>
 43        /// <remarks>Faster then <see cref="Enum.HasFlag"/>.</remarks>
 44        /// <param name="haystack">A predefined flag based enumeration.</param>
 45        /// <param name="needles">A set of flags to search for in the predefined enumeration.</param>
 46        /// <typeparam name="T">The enumeration's type.</typeparam>
 47        /// <returns>true if the needles are found in the haystack, otherwise false.</returns>
 48        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 49        public static unsafe bool HasFlags<T>(this T haystack, T needles) where T : unmanaged, Enum
 050        {
 051            return HasFlags(&haystack, &needles);
 052        }
 53    }
 54}

Methods/Properties

HasFlags[T](, )
HasFlags[T](T, T)