< Summary

Class:ReactiveUI.Validation.Extensions.ExpressionExtensions
Assembly:ReactiveUI.Validation
File(s):D:\a\1\s\src\ReactiveUI.Validation\Extensions\ExpressionExtensions.cs
Covered lines:8
Uncovered lines:0
Coverable lines:8
Total lines:44
Line coverage:100% (8 of 8)
Covered branches:4
Total branches:4
Branch coverage:100% (4 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
GetPropertyPath(...)-100%100%

File(s)

D:\a\1\s\src\ReactiveUI.Validation\Extensions\ExpressionExtensions.cs

#LineLine coverage
 1// Copyright (c) 2020 .NET Foundation and Contributors. All rights reserved.
 2// Licensed to the .NET Foundation under one or more agreements.
 3// The .NET Foundation licenses this file to you under the MIT license.
 4// See the LICENSE file in the project root for full license information.
 5
 6using System.Linq.Expressions;
 7using System.Text;
 8
 9namespace ReactiveUI.Validation.Extensions
 10{
 11    /// <summary>
 12    /// Extensions methods associated to <see cref="Expression"/> instances.
 13    /// </summary>
 14    internal static class ExpressionExtensions
 15    {
 16        /// <summary>
 17        /// Returns a property path expression as a string.
 18        /// </summary>
 19        /// <param name="expression">The property path expression.</param>
 20        /// <returns>The property path string representing the expression.</returns>
 21        /// <remarks>
 22        /// For more info see:
 23        /// https://github.com/reactiveui/ReactiveUI.Validation/issues/60
 24        /// This is a helper method.
 25        /// </remarks>
 26        public static string GetPropertyPath(this Expression expression)
 27        {
 8828            var path = new StringBuilder();
 18829            while (expression is MemberExpression memberExpression)
 30            {
 10031                if (path.Length > 0)
 32                {
 1233                    path.Insert(0, '.');
 34                }
 35
 10036                path.Insert(0, memberExpression.Member.Name);
 37
 10038                expression = memberExpression.Expression;
 10039            }
 40
 8841            return path.ToString();
 42        }
 43    }
 44}

Methods/Properties

GetPropertyPath(...)