< Summary

Information
Class: Syki.Shared.EnumExtensions
Assembly: Shared
File(s): /home/runner/work/syki/syki/Shared/Extensions/EnumExtensions.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 69
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetDescription(...)100%66100%
IsIn(...)100%44100%
ToEnum(...)100%11100%
IsValid(...)100%11100%
Is(...)100%11100%
DiffInMinutes(...)100%22100%

File(s)

/home/runner/work/syki/syki/Shared/Extensions/EnumExtensions.cs

#LineLine coverage
 1using System.ComponentModel;
 2
 3namespace Syki.Shared;
 4
 5public static class EnumExtensions
 6{
 7    public static string GetDescription(this Enum value)
 8    {
 153859        if (value == null)
 10        {
 111            return string.Empty;
 12        }
 13
 1538414        var attribute = value.GetType()
 1538415            .GetField(value.ToString())!
 1538416            .GetCustomAttributes(typeof(DescriptionAttribute), inherit: false);
 17
 1538418        if (attribute is DescriptionAttribute[] source && source.Length != 0)
 19        {
 1538320            return source.First().Description;
 21        }
 22
 123        return value.ToString();
 24    }
 25
 26    public static bool IsIn(this Enum source, params Enum[] valuesToCheck)
 27    {
 1228        if (valuesToCheck == null || valuesToCheck.Length == 0)
 29        {
 230            return false;
 31        }
 32
 1033        return valuesToCheck.Contains(source);
 34    }
 35
 36    public static T ToEnum<T>(this string value)
 37    {
 549838        return (T)Enum.Parse(typeof(T), value, true);
 39    }
 40
 41    public static bool IsValid(this Enum value)
 42    {
 108943        return Enum.IsDefined(value.GetType(), value);
 44    }
 45
 46    public static bool Is(this DayOfWeek dayOfWeek, Day day)
 47    {
 3029248        return day.ToString() == dayOfWeek.ToString();
 49    }
 50
 51    public static int DiffInMinutes(this Hour hourA, Hour hourB)
 52    {
 433653        if (hourA > hourB)
 54        {
 455            (hourA, hourB) = (hourB, hourA);
 56        }
 57
 433658        var hourAHour = int.Parse(hourA.ToString().Substring(1, 2));
 433659        var hourAMinute = int.Parse(hourA.ToString().Substring(4, 2));
 60
 433661        var hourBHour = int.Parse(hourB.ToString().Substring(1, 2));
 433662        var hourBMinute = int.Parse(hourB.ToString().Substring(4, 2));
 63
 433664        var hours = hourBHour - hourAHour;
 433665        var minutes = hourBMinute - hourAMinute;
 66
 433667        return hours * 60 + minutes;
 68    }
 69}