< Summary

Class:MainScripts.DCL.Helpers.Utils.EnumUtils
Assembly:Utils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/EnumUtils.cs
Covered lines:3
Uncovered lines:14
Coverable lines:17
Total lines:56
Line coverage:17.6% (3 of 17)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HasFlag[T](...)0%16.676033.33%
Max[T](...)0%42600%
Values[T]()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/EnumUtils.cs

#LineLine coverage
 1using System;
 2using System.Runtime.CompilerServices;
 3
 4namespace MainScripts.DCL.Helpers.Utils
 5{
 6    /// <summary>
 7    /// Contains non-allocating generic versions of enum utility functions
 8    /// </summary>
 9    public static class EnumUtils
 10    {
 11        public static unsafe bool HasFlag<T>(T x, T y) where T : unmanaged, Enum
 12        {
 96013            switch (sizeof(T))
 14            {
 15                case sizeof(byte):
 016                    return (*(byte*) &x & *(byte*) &y) != 0;
 17
 18                case sizeof(short):
 019                    return (*(short*) &x & *(short*) &y) != 0;
 20
 21                case sizeof(int):
 96022                    return (*(int*) &x & *(int*) &y) != 0;
 23
 24                case sizeof(long):
 025                    return (*(long*) &x & *(long*) &y) != 0L;
 26
 27                default:
 028                    return false;
 29            }
 30        }
 31
 32        public static unsafe T Max<T>(T x, T y) where T : unmanaged, Enum
 33        {
 034            switch (sizeof(T))
 35            {
 36                case sizeof(byte):
 037                    var b = Math.Max(*(byte*) &x, *(byte*) &y);
 038                    return Unsafe.As<byte, T>(ref b);
 39                case sizeof(short):
 040                    var s = Math.Max(*(short*) &x, *(short*) &y);
 041                    return Unsafe.As<short, T>(ref s);
 42                case sizeof(int):
 043                    var i = Math.Max(*(int*) &x, *(int*) &y);
 044                    return Unsafe.As<int, T>(ref i);
 45                case sizeof(long):
 046                    var l = Math.Max(*(long*) &x, *(long*) &y);
 047                    return Unsafe.As<long, T>(ref l);
 48                default:
 049                    throw new NotImplementedException(sizeof(T).ToString());
 50            }
 51        }
 52
 53        public static T[] Values<T>() =>
 154            (T[]) Enum.GetValues(typeof(T));
 55    }
 56}