| | | 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 | | |
| | | 6 | | using System.Linq.Expressions; |
| | | 7 | | using System.Text; |
| | | 8 | | |
| | | 9 | | namespace 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 | | { |
| | 88 | 28 | | var path = new StringBuilder(); |
| | 188 | 29 | | while (expression is MemberExpression memberExpression) |
| | | 30 | | { |
| | 100 | 31 | | if (path.Length > 0) |
| | | 32 | | { |
| | 12 | 33 | | path.Insert(0, '.'); |
| | | 34 | | } |
| | | 35 | | |
| | 100 | 36 | | path.Insert(0, memberExpression.Member.Name); |
| | | 37 | | |
| | 100 | 38 | | expression = memberExpression.Expression; |
| | 100 | 39 | | } |
| | | 40 | | |
| | 88 | 41 | | return path.ToString(); |
| | | 42 | | } |
| | | 43 | | } |
| | | 44 | | } |