-
Notifications
You must be signed in to change notification settings - Fork 3
/
YeSqlValidationResult.cs
71 lines (61 loc) · 2.03 KB
/
YeSqlValidationResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections.Generic;
using System.Text;
using System;
using System.Collections;
namespace YeSql.Net;
/// <summary>
/// Represents a container for the results of a validation.
/// </summary>
public class YeSqlValidationResult : IEnumerable<string>
{
/// <summary>
/// Allows access to the errors collection.
/// </summary>
private readonly List<string> _errors = new();
internal YeSqlValidationResult() { }
/// <summary>
/// Checks if there has been an error.
/// </summary>
/// <returns><c>true</c> if an error occurred, otherwise <c>false</c>.</returns>
public bool HasError()
=> _errors.Count > 0;
/// <summary>
/// Gets the number of errors contained in the container.
/// </summary>
public int Count => _errors.Count;
/// <summary>
/// Gets the error messages.
/// </summary>
public string ErrorMessages
{
get
{
if (_errors.Count == 0)
return string.Empty;
var stringBuilder = new StringBuilder();
foreach (var error in _errors)
stringBuilder.Append(error + Environment.NewLine);
return stringBuilder
.ToString()
.TrimEnd(Environment.NewLine.ToCharArray());
}
}
/// <summary>
/// Adds the error message to the collection.
/// </summary>
/// <param name="errorMessage">The message that describes the error.</param>
internal void Add(string errorMessage)
=> _errors.Add(errorMessage);
/// <summary>
/// Returns an enumerator that iterates through the errors contained in the container.
/// </summary>
/// <returns>An enumerator that can be used to iterate through the errors contained in the container.</returns>
public IEnumerator<string> GetEnumerator()
{
foreach (var error in _errors)
yield return error;
}
/// <inheritdoc cref="GetEnumerator" />
IEnumerator IEnumerable.GetEnumerator()
=> this.GetEnumerator();
}