forked from xoofx/SharpYaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYamlDerivedType.cs
More file actions
74 lines (63 loc) · 2.72 KB
/
YamlDerivedType.cs
File metadata and controls
74 lines (63 loc) · 2.72 KB
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
72
73
74
// // Copyright (c) Alexandre Mutel. All rights reserved.
// // Licensed under the MIT license.
// // See LICENSE.txt file in the project root for full license information.
using System;
using System.Globalization;
namespace SharpYaml;
/// <summary>
/// Represents a derived type mapping for runtime polymorphic configuration.
/// </summary>
public sealed class YamlDerivedType
{
/// <summary>
/// Initializes a new instance with no discriminator.
/// When <see cref="Tag"/> is also <see langword="null"/>, this derived type becomes the default
/// when no discriminator or tag matches. When <see cref="Tag"/> is set, this entry participates
/// only in tag-based dispatch and does not become the default.
/// </summary>
/// <param name="derivedType">The derived CLR type.</param>
/// <exception cref="ArgumentNullException"><paramref name="derivedType"/> is <see langword="null"/>.</exception>
public YamlDerivedType(Type derivedType)
{
ArgumentGuard.ThrowIfNull(derivedType);
DerivedType = derivedType;
Discriminator = null;
}
/// <summary>
/// Initializes a new instance with a string discriminator.
/// </summary>
/// <param name="derivedType">The derived CLR type.</param>
/// <param name="discriminator">The discriminator value.</param>
/// <exception cref="ArgumentNullException"><paramref name="derivedType"/> or <paramref name="discriminator"/> is <see langword="null"/>.</exception>
public YamlDerivedType(Type derivedType, string discriminator)
{
ArgumentGuard.ThrowIfNull(derivedType);
ArgumentGuard.ThrowIfNull(discriminator);
DerivedType = derivedType;
Discriminator = discriminator;
}
/// <summary>
/// Initializes a new instance with an integer discriminator.
/// </summary>
/// <param name="derivedType">The derived CLR type.</param>
/// <param name="discriminator">The integer discriminator value.</param>
/// <exception cref="ArgumentNullException"><paramref name="derivedType"/> is <see langword="null"/>.</exception>
public YamlDerivedType(Type derivedType, int discriminator)
{
ArgumentGuard.ThrowIfNull(derivedType);
DerivedType = derivedType;
Discriminator = discriminator.ToString(CultureInfo.InvariantCulture);
}
/// <summary>
/// Gets the derived CLR type.
/// </summary>
public Type DerivedType { get; }
/// <summary>
/// Gets the discriminator value, or <see langword="null"/> if this is the default derived type.
/// </summary>
public string? Discriminator { get; }
/// <summary>
/// Gets or sets an optional explicit YAML tag for the derived type.
/// </summary>
public string? Tag { get; init; }
}