Skip to content

Commit 4693d3d

Browse files
committed
add xml comments for uniqueKey
1 parent db00544 commit 4693d3d

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

YamlDotNet/Serialization/BufferedDeserialization/TypeDiscriminators/UniqueKeyTypeDiscriminator.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@
77

88
namespace YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators
99
{
10+
/// <summary>
11+
/// A TypeDiscriminator that discriminates which type to deserialize a yaml stream into by checking the existence
12+
/// of specific keys.
13+
/// </summary>
1014
public class UniqueKeyTypeDiscriminator : ITypeDiscriminator
1115
{
1216
public Type BaseType { get; private set; }
1317

1418
private readonly IDictionary<string, Type> typeMapping;
1519

20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="UniqueKeyTypeDiscriminator"/> class.
22+
/// The UniqueKeyTypeDiscriminator will check if any of the keys specified exist, and discriminate the coresponding type.
23+
/// </summary>
24+
/// <param name="baseType">The base type which all discriminated types will implement. Use object if you're discriminating
25+
/// unrelated types. Note the less specific you are with the base type the more yaml will need to be buffered.</param>
26+
/// <param name="typeMapping">A mapping dictionary of yaml keys to types.</param>
27+
/// <exception cref="ArgumentOutOfRangeException">If any of the target types do not implement the base type.</exception>
1628
public UniqueKeyTypeDiscriminator(Type baseType, IDictionary<string, Type> typeMapping)
1729
{
1830
foreach (var keyValuePair in typeMapping)
@@ -26,6 +38,17 @@ public UniqueKeyTypeDiscriminator(Type baseType, IDictionary<string, Type> typeM
2638
this.typeMapping = typeMapping;
2739
}
2840

41+
/// <summary>
42+
/// Checks if the current parser contains of the unique keys this discriminator has in it's type mapping.
43+
/// If so, return true, and the matching type.
44+
/// Otherwise, return false.
45+
/// This will consume the parser, so you will usually need the parser to be a buffer so an instance
46+
/// of the discriminated type can be deserialized later.
47+
/// </summary>
48+
/// <param name="parser">The IParser to consume and discriminate a type from.</param>
49+
/// <param name="suggestedType">The output type discriminated. Null if there target key was not present of if the value
50+
/// of the target key was not within the type mapping.</param>
51+
/// <returns>Returns true if the discriminator matched the yaml stream.</returns>
2952
public bool TryDiscriminate(IParser parser, out Type? suggestedType)
3053
{
3154
if (parser.TryFindMappingEntry(

0 commit comments

Comments
 (0)