< Summary - Code Coverage

Information
Class: Plainquire.Sort.ExpressionExtensions
Assembly: Plainquire.Sort
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Sort/Plainquire.Sort/Extensions/ExpressionExtensions.cs
Tag: 64_13932151703
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 51
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Total methods: 2
Method coverage: 100%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetPropertyPath(...)100%1212100%
UnboxBody(...)100%44100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq.Expressions;
 4
 5namespace Plainquire.Sort;
 6
 7/// <summary>
 8/// Extension methods for <see cref="Expression"/>.
 9/// </summary>
 10internal static class ExpressionExtensions
 11{
 12    /// <summary>
 13    /// Gets the path to a property (e.g. person.Address.Street).
 14    /// </summary>
 15    /// <typeparam name="TEntity">The entity that declares <typeparamref name="TProperty"/>.</typeparam>
 16    /// <typeparam name="TProperty">The type of the property.</typeparam>
 17    /// <param name="property">The property to get the access path to.</param>
 18    /// <exception cref="ArgumentException"></exception>
 19    public static string GetPropertyPath<TEntity, TProperty>(this Expression<Func<TEntity, TProperty>> property)
 20    {
 15821        var body = property.UnboxBody();
 22
 15823        if (body is ParameterExpression)
 124            return PropertySort.PATH_TO_SELF;
 25
 15726        if (body is not MemberExpression currentProperty)
 127            throw new ArgumentException("Given property must be a chain of property access expressions like person => pe
 28
 15629        var properties = new List<string>();
 20530        while (currentProperty is { Expression: MemberExpression } memberAccessExpression)
 31        {
 4932            properties.Add(memberAccessExpression.Member.Name);
 4933            currentProperty = (MemberExpression)memberAccessExpression.Expression;
 4934        }
 35
 15636        if (currentProperty is not { Expression: ParameterExpression } parameterExpression)
 137            throw new ArgumentException("Given property must be a chain of property access expressions like person => pe
 38
 15539        properties.Add(parameterExpression.Member.Name);
 40
 15541        properties.Reverse();
 15542        return string.Join('.', properties);
 43    }
 44
 45    private static Expression UnboxBody<TEntity, TProperty>(this Expression<Func<TEntity, TProperty>> property)
 46    {
 15847        if (property.Body is UnaryExpression { NodeType: ExpressionType.Convert } convert)
 2448            return convert.Operand;
 13449        return property.Body;
 50    }
 51}