Skip to content

Commit

Permalink
rename to TypeDiscriminatingNodeDeserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ11teen committed Mar 10, 2023
1 parent 5a01713 commit 13919ac
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void KeyValueTypeDiscriminator_WithParentBaseType_Single()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddKeyValueTypeDiscriminator<KubernetesResource>(
"kind",
new Dictionary<string, Type>()
Expand All @@ -38,7 +38,7 @@ public void KeyValueTypeDiscriminator_WithParentBaseType_List()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddKeyValueTypeDiscriminator<KubernetesResource>(
"kind",
new Dictionary<string, Type>()
Expand All @@ -61,7 +61,7 @@ public void KeyValueTypeDiscriminator_WithObjectBaseType_Single()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddKeyValueTypeDiscriminator<object>(
"kind",
new Dictionary<string, Type>()
Expand All @@ -83,7 +83,7 @@ public void KeyValueTypeDiscriminator_WithObjectBaseType_List()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddKeyValueTypeDiscriminator<object>(
"kind",
new Dictionary<string, Type>()
Expand All @@ -106,7 +106,7 @@ public void KeyValueTypeDiscriminator_WithInterfaceBaseType_Single()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddKeyValueTypeDiscriminator<IKubernetesResource>(
"kind",
new Dictionary<string, Type>()
Expand All @@ -128,7 +128,7 @@ public void KeyValueTypeDiscriminator_WithInterfaceBaseType_List()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddKeyValueTypeDiscriminator<IKubernetesResource>(
"kind",
new Dictionary<string, Type>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

namespace YamlDotNet.Test.Serialization.BufferedDeserialization
{
public class BufferedNodeDeserializerTests
public class TypeDiscriminatingNodeDeserializerTests
{
[Fact]
public void BufferedNodeDeserializer_ThrowsWhen_MaxDepthExceeded()
public void TypeDiscriminatingNodeDeserializer_ThrowsWhen_MaxDepthExceeded()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddKeyValueTypeDiscriminator<object>("kind", new Dictionary<string, Type>());
},
maxDepth: 2,
Expand All @@ -32,11 +32,11 @@ public void BufferedNodeDeserializer_ThrowsWhen_MaxDepthExceeded()
}

[Fact]
public void BufferedNodeDeserializer_ThrowsWhen_MaxLengthExceeded()
public void TypeDiscriminatingNodeDeserializer_ThrowsWhen_MaxLengthExceeded()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddKeyValueTypeDiscriminator<object>("kind", new Dictionary<string, Type>());
},
maxDepth: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void UniqueKeyTypeDiscriminator_WithInterfaceBaseType()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddUniqueKeyTypeDiscriminator<ICharacter>(
new Dictionary<string, Type>()
{
Expand All @@ -39,7 +39,7 @@ public void UniqueKeyTypeDiscriminator_WithObjectBaseType()
{
var bufferedDeserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithBufferedNodeDeserializer(options => {
.WithTypeDiscriminatingNodeDeserializer(options => {
options.AddUniqueKeyTypeDiscriminator<object>(
new Dictionary<string, Type>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace YamlDotNet.Serialization.BufferedDeserialization
{
public interface IBufferedNodeDeserializerOptions
public interface ITypeDiscriminatingNodeDeserializerOptions
{
public void AddTypeDiscriminator(ITypeDiscriminator discriminator);
public void AddKeyValueTypeDiscriminator<T>(string discriminatorKey, IDictionary<string, Type> valueTypeMapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
namespace YamlDotNet.Serialization.BufferedDeserialization
{
/// <summary>
/// The BufferedNodeDeserializer acts as a psuedo <see cref="INodeDeserializer" />.
/// If any of it's <see cref="ITypeDiscriminator" /> has a matching BaseType, the BufferedNodeDeserializer will
/// The TypeDiscriminatingNodeDeserializer acts as a psuedo <see cref="INodeDeserializer" />.
/// If any of it's <see cref="ITypeDiscriminator" /> has a matching BaseType, the TypeDiscriminatingNodeDeserializer will
/// begin buffering the yaml stream. It will then use the matching <see cref="ITypeDiscriminator" />s to determine
/// a dotnet output type for the yaml node. As the node is buffered, the <see cref="ITypeDiscriminator" />s are
/// able to examine the actual values within, and use these when discriminating a type.
/// Once a matching type is found, the BufferedNodeDeserializer uses it's inner deserializers to perform
/// Once a matching type is found, the TypeDiscriminatingNodeDeserializer uses it's inner deserializers to perform
/// the final deserialization for that type & object.
/// Usually you will want all default <see cref="INodeDeserializer" />s that exist in the outer
/// <see cref="Deserializer" /> to also be used as inner deserializers.
/// </summary>
public class BufferedNodeDeserializer : INodeDeserializer
public class TypeDiscriminatingNodeDeserializer : INodeDeserializer
{
private readonly IList<INodeDeserializer> innerDeserializers;
private readonly IList<ITypeDiscriminator> typeDiscriminators;
private readonly int maxDepthToBuffer;
private readonly int maxLengthToBuffer;

public BufferedNodeDeserializer(IList<INodeDeserializer> innerDeserializers, IList<ITypeDiscriminator> typeDiscriminators, int maxDepthToBuffer, int maxLengthToBuffer)
public TypeDiscriminatingNodeDeserializer(IList<INodeDeserializer> innerDeserializers, IList<ITypeDiscriminator> typeDiscriminators, int maxDepthToBuffer, int maxLengthToBuffer)
{
this.innerDeserializers = innerDeserializers;
this.typeDiscriminators = typeDiscriminators;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace YamlDotNet.Serialization.BufferedDeserialization
{
public class BufferedNodeDeserializerOptions : IBufferedNodeDeserializerOptions
public class TypeDiscriminatingNodeDeserializerOptions : ITypeDiscriminatingNodeDeserializerOptions
{
internal readonly List<ITypeDiscriminator> discriminators = new List<ITypeDiscriminator>();

/// <summary>
/// Adds an <see cref="ITypeDiscriminator" /> to be checked by the BufferedNodeDeserializer.
/// Adds an <see cref="ITypeDiscriminator" /> to be checked by the TypeDiscriminatingNodeDeserializer.
/// </summary>
/// <param name="discriminator">The <see cref="ITypeDiscriminator" /> to add.</param>
public void AddTypeDiscriminator(ITypeDiscriminator discriminator)
Expand All @@ -21,7 +21,7 @@ public void AddTypeDiscriminator(ITypeDiscriminator discriminator)
}

/// <summary>
/// Adds a <see cref="KeyValueTypeDiscriminator" /> to be checked by the BufferedNodeDeserializer.
/// Adds a <see cref="KeyValueTypeDiscriminator" /> to be checked by the TypeDiscriminatingNodeDeserializer.
/// <see cref="KeyValueTypeDiscriminator" />s use the value of a specified key on the yaml object to map
/// to a target type.
/// </summary>
Expand All @@ -33,7 +33,7 @@ public void AddKeyValueTypeDiscriminator<T>(string discriminatorKey, IDictionary
}

/// <summary>
/// Adds a <see cref="UniqueKeyTypeDiscriminator" /> to be checked by the BufferedNodeDeserializer.
/// Adds a <see cref="UniqueKeyTypeDiscriminator" /> to be checked by the TypeDiscriminatingNodeDeserializer.
/// <see cref="UniqueKeyTypeDiscriminator" />s use the presence of unique keys on the yaml object to map
/// to different target types.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators
{
/// <summary>
/// An ITypeDiscriminator provides an interface for discriminating which dotnet type to deserialize a yaml
/// stream into. They require the yaml stream to be buffered <see cref="BufferedNodeDeserializer" /> as they
/// stream into. They require the yaml stream to be buffered <see cref="TypeDiscriminatingNodeDeserializer" /> as they
/// can inspect the yaml value, determine the desired type, and reset the yaml stream to then deserialize into
/// that type.
/// </summary>
Expand Down
22 changes: 11 additions & 11 deletions YamlDotNet/Serialization/DeserializerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,25 +248,25 @@ public DeserializerBuilder WithoutNodeDeserializer(Type nodeDeserializerType)
}

/// <summary>
/// Registers a <see cref="BufferedNodeDeserializer" /> to be used by the deserializer. This internally registers
/// all existing <see cref="INodeDeserializer" /> as inner deserializers available to the <see cref="BufferedNodeDeserializer" />.
/// Registers a <see cref="TypeDiscriminatingNodeDeserializer" /> to be used by the deserializer. This internally registers
/// all existing <see cref="INodeDeserializer" /> as inner deserializers available to the <see cref="TypeDiscriminatingNodeDeserializer" />.
/// Usually you will want to call this after any other changes to the <see cref="INodeDeserializer" />s used by the deserializer.
/// </summary>
/// <param name="configureBufferedNodeDeserializerOptions">An action that can configure the <see cref="BufferedNodeDeserializer" />.</param>
/// <param name="configureTypeDiscriminatingNodeDeserializerOptions">An action that can configure the <see cref="TypeDiscriminatingNodeDeserializer" />.</param>
/// <param name="maxDepth">Configures the max depth of yaml nodes that will be buffered. A value of -1 (the default) means yaml nodes of any depth will be buffered.</param>
/// <param name="maxLength">Configures the max number of yaml nodes that will be buffered. A value of -1 (the default) means there is no limit on the number of yaml nodes buffered.</param>
public DeserializerBuilder WithBufferedNodeDeserializer(
Action<IBufferedNodeDeserializerOptions> configureBufferedNodeDeserializerOptions, int maxDepth = -1, int maxLength = -1)
public DeserializerBuilder WithTypeDiscriminatingNodeDeserializer(
Action<ITypeDiscriminatingNodeDeserializerOptions> configureTypeDiscriminatingNodeDeserializerOptions, int maxDepth = -1, int maxLength = -1)
{
var options = new BufferedNodeDeserializerOptions();
configureBufferedNodeDeserializerOptions(options);
// We use all current NodeDeserializers as the inner deserializers for the BufferedNodeDeserializer,
var options = new TypeDiscriminatingNodeDeserializerOptions();
configureTypeDiscriminatingNodeDeserializerOptions(options);
// We use all current NodeDeserializers as the inner deserializers for the TypeDiscriminatingNodeDeserializer,
// so that it can successfully deserialize anything our root deserializer can.
var bufferedNodeDeserializer = new BufferedNodeDeserializer(nodeDeserializerFactories.BuildComponentList(), options.discriminators, maxDepth, maxLength);
var TypeDiscriminatingNodeDeserializer = new TypeDiscriminatingNodeDeserializer(nodeDeserializerFactories.BuildComponentList(), options.discriminators, maxDepth, maxLength);

// We register this before the DictionaryNodeDeserializer, as otherwise it will take precedence
// and cases where BaseType = object will not reach the BufferedNodeDeserializer
return WithNodeDeserializer(bufferedNodeDeserializer, s => s.Before<DictionaryNodeDeserializer>());
// and cases where BaseType = object will not reach the TypeDiscriminatingNodeDeserializer
return WithNodeDeserializer(TypeDiscriminatingNodeDeserializer, s => s.Before<DictionaryNodeDeserializer>());
}

/// <summary>
Expand Down
22 changes: 11 additions & 11 deletions YamlDotNet/Serialization/StaticDeserializerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,25 @@ public StaticDeserializerBuilder WithoutNodeDeserializer(Type nodeDeserializerTy
}

/// <summary>
/// Registers a <see cref="BufferedNodeDeserializer" /> to be used by the deserializer. This internally registers
/// all existing <see cref="INodeDeserializer" /> as inner deserializers available to the <see cref="BufferedNodeDeserializer" />.
/// Registers a <see cref="TypeDiscriminatingNodeDeserializer" /> to be used by the deserializer. This internally registers
/// all existing <see cref="INodeDeserializer" /> as inner deserializers available to the <see cref="TypeDiscriminatingNodeDeserializer" />.
/// Usually you will want to call this after any other changes to the <see cref="INodeDeserializer" />s used by the deserializer.
/// </summary>
/// <param name="configureBufferedNodeDeserializerOptions">An action that can configure the <see cref="BufferedNodeDeserializer" />.</param>
/// <param name="configureTypeDiscriminatingNodeDeserializerOptions">An action that can configure the <see cref="TypeDiscriminatingNodeDeserializer" />.</param>
/// <param name="maxDepth">Configures the max depth of yaml nodes that will be buffered. A value of -1 (the default) means yaml nodes of any depth will be buffered.</param>
/// <param name="maxLength">Configures the max number of yaml nodes that will be buffered. A value of -1 (the default) means there is no limit on the number of yaml nodes buffered.</param>
public StaticDeserializerBuilder WithBufferedNodeDeserializer(
Action<IBufferedNodeDeserializerOptions> configureBufferedNodeDeserializerOptions, int maxDepth = -1, int maxLength = -1)
public StaticDeserializerBuilder WithTypeDiscriminatingNodeDeserializer(
Action<ITypeDiscriminatingNodeDeserializerOptions> configureTypeDiscriminatingNodeDeserializerOptions, int maxDepth = -1, int maxLength = -1)
{
var options = new BufferedNodeDeserializerOptions();
configureBufferedNodeDeserializerOptions(options);
// We use all current NodeDeserializers as the inner deserializers for the BufferedNodeDeserializer,
var options = new TypeDiscriminatingNodeDeserializerOptions();
configureTypeDiscriminatingNodeDeserializerOptions(options);
// We use all current NodeDeserializers as the inner deserializers for the TypeDiscriminatingNodeDeserializer,
// so that it can successfully deserialize anything our root deserializer can.
var bufferedNodeDeserializer = new BufferedNodeDeserializer(nodeDeserializerFactories.BuildComponentList(), options.discriminators, maxDepth, maxLength);
var TypeDiscriminatingNodeDeserializer = new TypeDiscriminatingNodeDeserializer(nodeDeserializerFactories.BuildComponentList(), options.discriminators, maxDepth, maxLength);

// We register this before the DictionaryNodeDeserializer, as otherwise it will take precedence
// and cases where BaseType = object will not reach the BufferedNodeDeserializer
return WithNodeDeserializer(bufferedNodeDeserializer, s => s.Before<DictionaryNodeDeserializer>());
// and cases where BaseType = object will not reach the TypeDiscriminatingNodeDeserializer
return WithNodeDeserializer(TypeDiscriminatingNodeDeserializer, s => s.Before<DictionaryNodeDeserializer>());
}

/// <summary>
Expand Down

0 comments on commit 13919ac

Please sign in to comment.