< Summary - SonghayCore

Information
Class: Songhay.Extensions.EnumExtensions
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/EnumExtensions.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 41
Line coverage: 100%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
GetEnumDescription(...)50%6100%
GetEnumValues(...)100%1100%

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/EnumExtensions.cs

#LineLine coverage
 1using System.ComponentModel;
 2
 3namespace Songhay.Extensions;
 4
 5/// <summary>
 6/// Extensions of <see cref="Enum"/>.
 7/// </summary>
 8public static class EnumExtensions
 9{
 10    /// <summary>
 11    /// Gets any conventional <see cref="DescriptionAttribute.Description"/>
 12    /// applied to an <see cref="Enum"/>.
 13    /// </summary>
 14    /// <param name="value">The <see cref="Enum"/>.</param>
 15    public static string? GetEnumDescription(this Enum value)
 116    {
 117        var enumType = value.GetType();
 118        var enumName = Enum.GetName(enumType, value);
 119        if (enumName == null) return null;
 20
 121        FieldInfo? field = enumType.GetField(enumName);
 122        if (field == null) return null;
 23
 124        var attr = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
 25
 126        return attr?.Description;
 127    }
 28
 29    /// <summary>
 30    /// Gets the result of <see cref="Enum.GetValues"/>
 31    /// based on the specified <see cref="Enum"/>.
 32    /// </summary>
 33    /// <param name="value">The <see cref="Enum"/>.</param>
 34    public static IEnumerable<Enum> GetEnumValues(this Enum value)
 135    {
 136        var enumType = value.GetType();
 137        var enums = Enum.GetValues(enumType).OfType<Enum>();
 38
 139        return enums;
 140    }
 41}