| | | 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.Collections; |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | |
| | | 9 | | namespace ReactiveUI.Validation.Collections |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Container for validation text. |
| | | 13 | | /// </summary> |
| | | 14 | | public class ValidationText : IEnumerable<string> |
| | | 15 | | { |
| | 404 | 16 | | private readonly List<string> _texts = new List<string>(); |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="ValidationText"/> class. |
| | | 20 | | /// </summary> |
| | 66 | 21 | | public ValidationText() |
| | | 22 | | { |
| | 66 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Initializes a new instance of the <see cref="ValidationText"/> class. |
| | | 27 | | /// </summary> |
| | | 28 | | /// <param name="text">Text to be added in the collection.</param> |
| | 124 | 29 | | public ValidationText(string text) |
| | | 30 | | { |
| | 124 | 31 | | _texts.Add(text); |
| | 124 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Initializes a new instance of the <see cref="ValidationText"/> class. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="validationTexts"><see cref="ValidationText"/> collection to be added into the text collection.< |
| | 214 | 38 | | public ValidationText(IEnumerable<ValidationText> validationTexts) |
| | | 39 | | { |
| | 214 | 40 | | if (validationTexts is null) |
| | | 41 | | { |
| | 0 | 42 | | throw new System.ArgumentNullException(nameof(validationTexts)); |
| | | 43 | | } |
| | | 44 | | |
| | 668 | 45 | | foreach (var text in validationTexts) |
| | | 46 | | { |
| | 120 | 47 | | _texts.AddRange(text._texts); |
| | | 48 | | } |
| | 214 | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Gets returns the number of elements in the collection. |
| | | 53 | | /// </summary> |
| | 12 | 54 | | public int Count => _texts.Count; |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Indexer. |
| | | 58 | | /// </summary> |
| | | 59 | | /// <param name="index">Position.</param> |
| | 6 | 60 | | public string this[int index] => _texts[index]; |
| | | 61 | | |
| | | 62 | | /// <inheritdoc/> |
| | | 63 | | public IEnumerator<string> GetEnumerator() |
| | | 64 | | { |
| | 18 | 65 | | return _texts.GetEnumerator(); |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <inheritdoc/> |
| | | 69 | | IEnumerator IEnumerable.GetEnumerator() |
| | | 70 | | { |
| | 0 | 71 | | return GetEnumerator(); |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Adds a text to the collection. |
| | | 76 | | /// </summary> |
| | | 77 | | /// <param name="text">Text to be added in the collection.</param> |
| | | 78 | | public void Add(string text) |
| | | 79 | | { |
| | 0 | 80 | | _texts.Add(text); |
| | 0 | 81 | | } |
| | | 82 | | |
| | | 83 | | /// <summary> |
| | | 84 | | /// Clear all texts. |
| | | 85 | | /// </summary> |
| | | 86 | | public void Clear() |
| | | 87 | | { |
| | 0 | 88 | | _texts.Clear(); |
| | 0 | 89 | | } |
| | | 90 | | |
| | | 91 | | /// <summary> |
| | | 92 | | /// Convert representation to a single line using a specified separator. |
| | | 93 | | /// </summary> |
| | | 94 | | /// <param name="separator">String separator.</param> |
| | | 95 | | /// <returns>Returns all the text collection separated by the separator.</returns> |
| | | 96 | | public string ToSingleLine(string? separator = ",") |
| | | 97 | | { |
| | 78 | 98 | | return string.Join(separator, _texts); |
| | | 99 | | } |
| | | 100 | | } |
| | | 101 | | } |