| | | 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 ReactiveUI.Validation.Collections; |
| | | 7 | | using ReactiveUI.Validation.Formatters.Abstractions; |
| | | 8 | | |
| | | 9 | | namespace ReactiveUI.Validation.Formatters |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | | 12 | | /// <summary> |
| | | 13 | | /// Helper class to generate a single formatted line for a <see cref="ReactiveUI.Validation.Collections.ValidationTe |
| | | 14 | | /// </summary> |
| | | 15 | | public class SingleLineFormatter : IValidationTextFormatter<string> |
| | | 16 | | { |
| | | 17 | | private readonly string? _separator; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Initializes a new instance of the <see cref="SingleLineFormatter"/> class. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="separator">Separator string.</param> |
| | 2 | 23 | | public SingleLineFormatter(string? separator = null) |
| | | 24 | | { |
| | 2 | 25 | | _separator = separator; |
| | 2 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets the default formatter. |
| | | 30 | | /// </summary> |
| | 26 | 31 | | public static SingleLineFormatter Default { get; } = new SingleLineFormatter(" "); |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Formats the <see cref="ValidationText"/> into a single line text using the |
| | | 35 | | /// default separator. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="validationText">ValidationText object to be formatted.</param> |
| | | 38 | | /// <returns>Returns the string formatted.</returns> |
| | | 39 | | public string Format(ValidationText validationText) |
| | | 40 | | { |
| | 40 | 41 | | return validationText != null |
| | 40 | 42 | | ? validationText.ToSingleLine(_separator) |
| | 40 | 43 | | : string.Empty; |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | } |