Import YamlDotNet.

This commit is contained in:
2022-12-12 22:23:49 +08:00
parent f559cea826
commit 1477e907e6
462 changed files with 27142 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Globalization;
using YamlDotNet.Core;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
public sealed class AnchorAssigner : PreProcessingPhaseObjectGraphVisitorSkeleton, IAliasProvider
{
private class AnchorAssignment
{
public AnchorName Anchor;
}
private readonly IDictionary<object, AnchorAssignment> assignments = new Dictionary<object, AnchorAssignment>();
private uint nextId;
public AnchorAssigner(IEnumerable<IYamlTypeConverter> typeConverters)
: base(typeConverters)
{
}
protected override bool Enter(IObjectDescriptor value)
{
if (value.Value != null && assignments.TryGetValue(value.Value, out var assignment))
{
if (assignment.Anchor.IsEmpty)
{
assignment.Anchor = new AnchorName("o" + nextId.ToString(CultureInfo.InvariantCulture));
++nextId;
}
return false;
}
return true;
}
protected override bool EnterMapping(IObjectDescriptor key, IObjectDescriptor value)
{
return true;
}
protected override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value)
{
return true;
}
protected override void VisitScalar(IObjectDescriptor scalar)
{
// Do not assign anchors to scalars
}
protected override void VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType)
{
VisitObject(mapping);
}
protected override void VisitMappingEnd(IObjectDescriptor mapping) { }
protected override void VisitSequenceStart(IObjectDescriptor sequence, Type elementType)
{
VisitObject(sequence);
}
protected override void VisitSequenceEnd(IObjectDescriptor sequence) { }
private void VisitObject(IObjectDescriptor value)
{
if (value.Value != null)
{
assignments.Add(value.Value, new AnchorAssignment());
}
}
AnchorName IAliasProvider.GetAlias(object target)
{
if (target != null && assignments.TryGetValue(target, out var assignment))
{
return assignment.Anchor;
}
return AnchorName.Empty;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c7a4420c17a267847b8d6973ad99346a
timeCreated: 1427145266
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,78 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using YamlDotNet.Core;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
public sealed class AnchorAssigningObjectGraphVisitor : ChainedObjectGraphVisitor
{
private readonly IEventEmitter eventEmitter;
private readonly IAliasProvider aliasProvider;
private readonly HashSet<AnchorName> emittedAliases = new HashSet<AnchorName>();
public AnchorAssigningObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor, IEventEmitter eventEmitter, IAliasProvider aliasProvider)
: base(nextVisitor)
{
this.eventEmitter = eventEmitter;
this.aliasProvider = aliasProvider;
}
public override bool Enter(IObjectDescriptor value, IEmitter context)
{
if (value.Value != null)
{
var alias = aliasProvider.GetAlias(value.Value);
if (!alias.IsEmpty && !emittedAliases.Add(alias))
{
var aliasEventInfo = new AliasEventInfo(value, alias);
eventEmitter.Emit(aliasEventInfo, context);
return aliasEventInfo.NeedsExpansion;
}
}
return base.Enter(value, context);
}
public override void VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType, IEmitter context)
{
var anchor = aliasProvider.GetAlias(mapping.NonNullValue());
eventEmitter.Emit(new MappingStartEventInfo(mapping) { Anchor = anchor }, context);
}
public override void VisitSequenceStart(IObjectDescriptor sequence, Type elementType, IEmitter context)
{
var anchor = aliasProvider.GetAlias(sequence.NonNullValue());
eventEmitter.Emit(new SequenceStartEventInfo(sequence) { Anchor = anchor }, context);
}
public override void VisitScalar(IObjectDescriptor scalar, IEmitter context)
{
var scalarInfo = new ScalarEventInfo(scalar);
if (scalar.Value != null)
{
scalarInfo.Anchor = aliasProvider.GetAlias(scalar.Value);
}
eventEmitter.Emit(scalarInfo, context);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7c8b5b39c74f14248971b3c1a4ec83b2
timeCreated: 1427145265
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using YamlDotNet.Core;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
public abstract class ChainedObjectGraphVisitor : IObjectGraphVisitor<IEmitter>
{
private readonly IObjectGraphVisitor<IEmitter> nextVisitor;
protected ChainedObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor)
{
this.nextVisitor = nextVisitor;
}
public virtual bool Enter(IObjectDescriptor value, IEmitter context)
{
return nextVisitor.Enter(value, context);
}
public virtual bool EnterMapping(IObjectDescriptor key, IObjectDescriptor value, IEmitter context)
{
return nextVisitor.EnterMapping(key, value, context);
}
public virtual bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
{
return nextVisitor.EnterMapping(key, value, context);
}
public virtual void VisitScalar(IObjectDescriptor scalar, IEmitter context)
{
nextVisitor.VisitScalar(scalar, context);
}
public virtual void VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType, IEmitter context)
{
nextVisitor.VisitMappingStart(mapping, keyType, valueType, context);
}
public virtual void VisitMappingEnd(IObjectDescriptor mapping, IEmitter context)
{
nextVisitor.VisitMappingEnd(mapping, context);
}
public virtual void VisitSequenceStart(IObjectDescriptor sequence, Type elementType, IEmitter context)
{
nextVisitor.VisitSequenceStart(sequence, elementType, context);
}
public virtual void VisitSequenceEnd(IObjectDescriptor sequence, IEmitter context)
{
nextVisitor.VisitSequenceEnd(sequence, context);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91c55744c252b51459a0c70f40c47827
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using YamlDotNet.Core;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
public sealed class CommentsObjectGraphVisitor : ChainedObjectGraphVisitor
{
public CommentsObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor)
: base(nextVisitor)
{
}
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
{
var yamlMember = key.GetCustomAttribute<YamlMemberAttribute>();
if (yamlMember?.Description != null)
{
context.Emit(new Core.Events.Comment(yamlMember.Description, false));
}
return base.EnterMapping(key, value, context);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dbe6fcb53ec2760458af35fda5494faa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,69 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System.Collections.Generic;
using System.Linq;
using YamlDotNet.Core;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
public sealed class CustomSerializationObjectGraphVisitor : ChainedObjectGraphVisitor
{
private readonly IEnumerable<IYamlTypeConverter> typeConverters;
private readonly ObjectSerializer nestedObjectSerializer;
public CustomSerializationObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor, IEnumerable<IYamlTypeConverter> typeConverters, ObjectSerializer nestedObjectSerializer)
: base(nextVisitor)
{
this.typeConverters = typeConverters != null
? typeConverters.ToList()
: Enumerable.Empty<IYamlTypeConverter>();
this.nestedObjectSerializer = nestedObjectSerializer;
}
public override bool Enter(IObjectDescriptor value, IEmitter context)
{
var typeConverter = typeConverters.FirstOrDefault(t => t.Accepts(value.Type));
if (typeConverter != null)
{
typeConverter.WriteYaml(context, value.Value, value.Type);
return false;
}
if (value.Value is IYamlConvertible convertible)
{
convertible.Write(context, nestedObjectSerializer);
return false;
}
#pragma warning disable 0618 // IYamlSerializable is obsolete
if (value.Value is IYamlSerializable serializable)
{
serializable.WriteYaml(context);
return false;
}
#pragma warning restore
return base.Enter(value, context);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 180ba37056bdea24393986bdab81340d
timeCreated: 1427145263
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.ComponentModel;
using YamlDotNet.Core;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
public sealed class DefaultExclusiveObjectGraphVisitor : ChainedObjectGraphVisitor
{
public DefaultExclusiveObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor)
: base(nextVisitor)
{
}
private static object? GetDefault(Type type)
{
return type.IsValueType() ? Activator.CreateInstance(type) : null;
}
public override bool EnterMapping(IObjectDescriptor key, IObjectDescriptor value, IEmitter context)
{
return !Equals(value.Value, GetDefault(value.Type))
&& base.EnterMapping(key, value, context);
}
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
{
var defaultValueAttribute = key.GetCustomAttribute<DefaultValueAttribute>();
var defaultValue = defaultValueAttribute != null
? defaultValueAttribute.Value
: GetDefault(key.Type);
return !Equals(value.Value, defaultValue)
&& base.EnterMapping(key, value, context);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6f0bed3472e6485468490ba7cf5c910e
timeCreated: 1427145264
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections;
using System.ComponentModel;
using YamlDotNet.Core;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
public sealed class DefaultValuesObjectGraphVisitor : ChainedObjectGraphVisitor
{
private readonly DefaultValuesHandling handling;
public DefaultValuesObjectGraphVisitor(DefaultValuesHandling handling, IObjectGraphVisitor<IEmitter> nextVisitor)
: base(nextVisitor)
{
this.handling = handling;
}
private static object? GetDefault(Type type)
{
return type.IsValueType() ? Activator.CreateInstance(type) : null;
}
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
{
var configuration = handling;
var yamlMember = key.GetCustomAttribute<YamlMemberAttribute>();
if (yamlMember != null && yamlMember.IsDefaultValuesHandlingSpecified)
{
configuration = yamlMember.DefaultValuesHandling;
}
if ((configuration & DefaultValuesHandling.OmitNull) != 0)
{
if (value.Value is null)
{
return false;
}
}
if ((configuration & DefaultValuesHandling.OmitEmptyCollections) != 0)
{
if (value.Value is IEnumerable enumerable)
{
var enumerator = enumerable.GetEnumerator();
var canMoveNext = enumerator.MoveNext();
if (enumerator is IDisposable disposable)
{
disposable.Dispose();
}
if (!canMoveNext)
{
return false;
}
}
}
if ((configuration & DefaultValuesHandling.OmitDefaults) != 0)
{
var defaultValue = key.GetCustomAttribute<DefaultValueAttribute>()?.Value ?? GetDefault(key.Type);
if (Equals(value.Value, defaultValue))
{
return false;
}
}
return base.EnterMapping(key, value, context);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 177b4ba5647b6a6468e0d186fd3b96e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using YamlDotNet.Core;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
public sealed class EmittingObjectGraphVisitor : IObjectGraphVisitor<IEmitter>
{
private readonly IEventEmitter eventEmitter;
public EmittingObjectGraphVisitor(IEventEmitter eventEmitter)
{
this.eventEmitter = eventEmitter;
}
bool IObjectGraphVisitor<IEmitter>.Enter(IObjectDescriptor value, IEmitter context)
{
return true;
}
bool IObjectGraphVisitor<IEmitter>.EnterMapping(IObjectDescriptor key, IObjectDescriptor value, IEmitter context)
{
return true;
}
bool IObjectGraphVisitor<IEmitter>.EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
{
return true;
}
void IObjectGraphVisitor<IEmitter>.VisitScalar(IObjectDescriptor scalar, IEmitter context)
{
eventEmitter.Emit(new ScalarEventInfo(scalar), context);
}
void IObjectGraphVisitor<IEmitter>.VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType, IEmitter context)
{
eventEmitter.Emit(new MappingStartEventInfo(mapping), context);
}
void IObjectGraphVisitor<IEmitter>.VisitMappingEnd(IObjectDescriptor mapping, IEmitter context)
{
eventEmitter.Emit(new MappingEndEventInfo(mapping), context);
}
void IObjectGraphVisitor<IEmitter>.VisitSequenceStart(IObjectDescriptor sequence, Type elementType, IEmitter context)
{
eventEmitter.Emit(new SequenceStartEventInfo(sequence), context);
}
void IObjectGraphVisitor<IEmitter>.VisitSequenceEnd(IObjectDescriptor sequence, IEmitter context)
{
eventEmitter.Emit(new SequenceEndEventInfo(sequence), context);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 23b01227eabbc3c4eb0e2658ac27b23d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,109 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
namespace YamlDotNet.Serialization.ObjectGraphVisitors
{
/// <summary>
/// A base class that simplifies the correct implementation of <see cref="IObjectGraphVisitor{Nothing}" />.
/// </summary>
public abstract class PreProcessingPhaseObjectGraphVisitorSkeleton : IObjectGraphVisitor<Nothing>
{
protected readonly IEnumerable<IYamlTypeConverter> typeConverters;
public PreProcessingPhaseObjectGraphVisitorSkeleton(IEnumerable<IYamlTypeConverter> typeConverters)
{
this.typeConverters = typeConverters != null
? typeConverters.ToList()
: Enumerable.Empty<IYamlTypeConverter>();
}
bool IObjectGraphVisitor<Nothing>.Enter(IObjectDescriptor value, Nothing context)
{
var typeConverter = typeConverters.FirstOrDefault(t => t.Accepts(value.Type));
if (typeConverter != null)
{
return false;
}
if (value.Value is IYamlConvertible convertible)
{
return false;
}
#pragma warning disable 0618 // IYamlSerializable is obsolete
if (value.Value is IYamlSerializable serializable)
{
return false;
}
#pragma warning restore
return Enter(value);
}
bool IObjectGraphVisitor<Nothing>.EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, Nothing context)
{
return EnterMapping(key, value);
}
bool IObjectGraphVisitor<Nothing>.EnterMapping(IObjectDescriptor key, IObjectDescriptor value, Nothing context)
{
return EnterMapping(key, value);
}
void IObjectGraphVisitor<Nothing>.VisitMappingEnd(IObjectDescriptor mapping, Nothing context)
{
VisitMappingEnd(mapping);
}
void IObjectGraphVisitor<Nothing>.VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType, Nothing context)
{
VisitMappingStart(mapping, keyType, valueType);
}
void IObjectGraphVisitor<Nothing>.VisitScalar(IObjectDescriptor scalar, Nothing context)
{
VisitScalar(scalar);
}
void IObjectGraphVisitor<Nothing>.VisitSequenceEnd(IObjectDescriptor sequence, Nothing context)
{
VisitSequenceEnd(sequence);
}
void IObjectGraphVisitor<Nothing>.VisitSequenceStart(IObjectDescriptor sequence, Type elementType, Nothing context)
{
VisitSequenceStart(sequence, elementType);
}
protected abstract bool Enter(IObjectDescriptor value);
protected abstract bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value);
protected abstract bool EnterMapping(IObjectDescriptor key, IObjectDescriptor value);
protected abstract void VisitMappingEnd(IObjectDescriptor mapping);
protected abstract void VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType);
protected abstract void VisitScalar(IObjectDescriptor scalar);
protected abstract void VisitSequenceEnd(IObjectDescriptor sequence);
protected abstract void VisitSequenceStart(IObjectDescriptor sequence, Type elementType);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58f47ab50428cf64e9f17e5cf1caee3a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: