< Summary - Code Coverage

Information
Class: Plainquire.Sort.TypeExtensions
Assembly: Plainquire.Sort
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Sort/Plainquire.Sort/Extensions/TypeExtensions.cs
Tag: 64_13932151703
Line coverage
91%
Covered lines: 11
Uncovered lines: 1
Coverable lines: 12
Total lines: 61
Line coverage: 91.6%
Branch coverage
68%
Covered branches: 11
Total branches: 16
Branch coverage: 68.7%
Method coverage
100%
Covered methods: 4
Total methods: 4
Method coverage: 100%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
IsNullable(...)66.66%6680%
IsGenericEntitySort(...)100%22100%
GetSortableProperties(...)100%11100%
IsPropertySortable(...)62.5%88100%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Sort/Plainquire.Sort/Extensions/TypeExtensions.cs

#LineLine coverage
 1using Plainquire.Filter.Abstractions;
 2using System;
 3using System.Collections;
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.Reflection;
 7
 8namespace Plainquire.Sort;
 9
 10/// <summary>
 11/// Extension methods for <see cref="Type"/>.
 12/// </summary>
 13internal static class TypeExtensions
 14{
 15    /// <summary>
 16    /// Returns <c>true</c> when the value of then given type can be <c>null</c>; otherwise <c>false</c>.
 17    /// </summary>
 18    /// <param name="type">The type to check.</param>
 19    /// <exception cref="ArgumentNullException"></exception>
 20    public static bool IsNullable(this Type type)
 21    {
 26522        if (type == null)
 023            throw new ArgumentNullException(nameof(type));
 24
 26525        if (type.IsClass)
 25626            return true;
 27
 928        return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
 29    }
 30
 31    /// <summary>
 32    /// Determines whether the given type is <see cref="EntitySort{TEntity}"/>.
 33    /// </summary>
 34    /// <param name="type">The type.</param>
 35    /// <autogeneratedoc />
 36    public static bool IsGenericEntitySort(this Type type)
 208837        => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(EntitySort<>);
 38
 39    /// <summary>
 40    /// Gets all properties sortable by <see cref="EntitySort"/>.
 41    /// </summary>
 42    /// <param name="type">The type.</param>
 43    /// <autogeneratedoc />
 44    public static IEnumerable<PropertyInfo> GetSortableProperties(this Type type)
 11345        => type.GetProperties().Where(property => property.IsPropertySortable());
 46
 47    /// <summary>
 48    /// Determines whether this parameter is visible as (MVC controller action) parameter.
 49    /// </summary>
 50    /// <param name="member">The member.</param>
 51    /// <autogeneratedoc />
 52    private static bool IsPropertySortable(this PropertyInfo member)
 53    {
 34654        var isEnumerable = member.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(member.Property
 34655        var filterAttribute = member.GetCustomAttribute<FilterAttribute>();
 56
 34657        return isEnumerable
 34658            ? filterAttribute?.Sortable == true
 34659            : filterAttribute?.Sortable != false;
 60    }
 61}