/
OptionsValidationException.cs
50 lines (43 loc) · 1.66 KB
/
OptionsValidationException.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
namespace Microsoft.Extensions.Options
{
/// <summary>
/// Thrown when options validation fails.
/// </summary>
public class OptionsValidationException : Exception
{
/// <summary>
/// Constructor.
/// </summary>
/// <param name="optionsName">The name of the options instance that failed.</param>
/// <param name="optionsType">The options type that failed.</param>
/// <param name="failureMessages">The validation failure messages.</param>
public OptionsValidationException(string optionsName, Type optionsType, IEnumerable<string>? failureMessages)
{
ThrowHelper.ThrowIfNull(optionsName);
ThrowHelper.ThrowIfNull(optionsType);
Failures = failureMessages ?? new List<string>();
OptionsType = optionsType;
OptionsName = optionsName;
}
/// <summary>
/// The name of the options instance that failed.
/// </summary>
public string OptionsName { get; }
/// <summary>
/// The type of the options that failed.
/// </summary>
public Type OptionsType { get; }
/// <summary>
/// The validation failures.
/// </summary>
public IEnumerable<string> Failures { get; }
/// <summary>
/// The message is a semicolon separated list of the <see cref="Failures"/>.
/// </summary>
public override string Message => string.Join("; ", Failures);
}
}