Import YamlDotNet.
This commit is contained in:
326
Assets/YamlDotNet/Serialization/BuilderSkeleton.cs
Normal file
326
Assets/YamlDotNet/Serialization/BuilderSkeleton.cs
Normal file
@@ -0,0 +1,326 @@
|
||||
// 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;
|
||||
using YamlDotNet.Serialization.Converters;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
using YamlDotNet.Serialization.TypeInspectors;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Common implementation of <see cref="SerializerBuilder" /> and <see cref="DeserializerBuilder" />.
|
||||
/// </summary>
|
||||
public abstract class BuilderSkeleton<TBuilder>
|
||||
where TBuilder : BuilderSkeleton<TBuilder>
|
||||
{
|
||||
internal INamingConvention namingConvention = NullNamingConvention.Instance;
|
||||
internal ITypeResolver typeResolver;
|
||||
internal readonly YamlAttributeOverrides overrides;
|
||||
internal readonly LazyComponentRegistrationList<Nothing, IYamlTypeConverter> typeConverterFactories;
|
||||
internal readonly LazyComponentRegistrationList<ITypeInspector, ITypeInspector> typeInspectorFactories;
|
||||
private bool ignoreFields;
|
||||
private bool includeNonPublicProperties = false;
|
||||
|
||||
internal BuilderSkeleton(ITypeResolver typeResolver)
|
||||
{
|
||||
overrides = new YamlAttributeOverrides();
|
||||
|
||||
typeConverterFactories = new LazyComponentRegistrationList<Nothing, IYamlTypeConverter>
|
||||
{
|
||||
{ typeof(GuidConverter), _ => new GuidConverter(false) },
|
||||
{ typeof(SystemTypeConverter), _ => new SystemTypeConverter() }
|
||||
};
|
||||
|
||||
typeInspectorFactories = new LazyComponentRegistrationList<ITypeInspector, ITypeInspector>();
|
||||
this.typeResolver = typeResolver ?? throw new ArgumentNullException(nameof(typeResolver));
|
||||
}
|
||||
|
||||
protected abstract TBuilder Self { get; }
|
||||
|
||||
internal ITypeInspector BuildTypeInspector()
|
||||
{
|
||||
ITypeInspector innerInspector = new ReadablePropertiesTypeInspector(typeResolver, includeNonPublicProperties);
|
||||
if (!ignoreFields)
|
||||
{
|
||||
innerInspector = new CompositeTypeInspector(
|
||||
new ReadableFieldsTypeInspector(typeResolver),
|
||||
innerInspector
|
||||
);
|
||||
}
|
||||
|
||||
return typeInspectorFactories.BuildComponentChain(innerInspector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prevents serialization and deserialization of fields.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public TBuilder IgnoreFields()
|
||||
{
|
||||
ignoreFields = true;
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows serialization and deserialization of non-public properties.
|
||||
/// </summary>
|
||||
public TBuilder IncludeNonPublicProperties()
|
||||
{
|
||||
includeNonPublicProperties = true;
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="INamingConvention" /> that will be used by the (de)serializer.
|
||||
/// </summary>
|
||||
public TBuilder WithNamingConvention(INamingConvention namingConvention)
|
||||
{
|
||||
this.namingConvention = namingConvention ?? throw new ArgumentNullException(nameof(namingConvention));
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="ITypeResolver" /> that will be used by the (de)serializer.
|
||||
/// </summary>
|
||||
public TBuilder WithTypeResolver(ITypeResolver typeResolver)
|
||||
{
|
||||
this.typeResolver = typeResolver ?? throw new ArgumentNullException(nameof(typeResolver));
|
||||
return Self;
|
||||
}
|
||||
|
||||
public abstract TBuilder WithTagMapping(TagName tag, Type type);
|
||||
|
||||
#if !NET20
|
||||
/// <summary>
|
||||
/// Register an <see cref="Attribute"/> for a given property.
|
||||
/// </summary>
|
||||
/// <typeparam name="TClass"></typeparam>
|
||||
/// <param name="propertyAccessor">An expression in the form: x => x.SomeProperty</param>
|
||||
/// <param name="attribute">The attribute to register.</param>
|
||||
/// <returns></returns>
|
||||
public TBuilder WithAttributeOverride<TClass>(System.Linq.Expressions.Expression<Func<TClass, object>> propertyAccessor, Attribute attribute)
|
||||
{
|
||||
overrides.Add(propertyAccessor, attribute);
|
||||
return Self;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Register an <see cref="Attribute"/> for a given property.
|
||||
/// </summary>
|
||||
public TBuilder WithAttributeOverride(Type type, string member, Attribute attribute)
|
||||
{
|
||||
overrides.Add(type, member, attribute);
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="IYamlTypeConverter" /> to be used by the (de)serializer.
|
||||
/// </summary>
|
||||
public TBuilder WithTypeConverter(IYamlTypeConverter typeConverter)
|
||||
{
|
||||
return WithTypeConverter(typeConverter, w => w.OnTop());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="IYamlTypeConverter" /> to be used by the (de)serializer.
|
||||
/// </summary>
|
||||
/// <param name="typeConverter"></param>
|
||||
/// <param name="where">Configures the location where to insert the <see cref="IYamlTypeConverter" /></param>
|
||||
public TBuilder WithTypeConverter(
|
||||
IYamlTypeConverter typeConverter,
|
||||
Action<IRegistrationLocationSelectionSyntax<IYamlTypeConverter>> where
|
||||
)
|
||||
{
|
||||
if (typeConverter == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(typeConverter));
|
||||
}
|
||||
|
||||
if (where == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(where));
|
||||
}
|
||||
|
||||
where(typeConverterFactories.CreateRegistrationLocationSelector(typeConverter.GetType(), _ => typeConverter));
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="IYamlTypeConverter" /> to be used by the (de)serializer.
|
||||
/// </summary>
|
||||
/// <param name="typeConverterFactory">A factory that creates the <see cref="IYamlTypeConverter" /> based on a previously registered <see cref="IYamlTypeConverter" />.</param>
|
||||
/// <param name="where">Configures the location where to insert the <see cref="IYamlTypeConverter" /></param>
|
||||
public TBuilder WithTypeConverter<TYamlTypeConverter>(
|
||||
WrapperFactory<IYamlTypeConverter, IYamlTypeConverter> typeConverterFactory,
|
||||
Action<ITrackingRegistrationLocationSelectionSyntax<IYamlTypeConverter>> where
|
||||
)
|
||||
where TYamlTypeConverter : IYamlTypeConverter
|
||||
{
|
||||
if (typeConverterFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(typeConverterFactory));
|
||||
}
|
||||
|
||||
if (where == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(where));
|
||||
}
|
||||
|
||||
where(typeConverterFactories.CreateTrackingRegistrationLocationSelector(typeof(TYamlTypeConverter), (wrapped, _) => typeConverterFactory(wrapped)));
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing <see cref="IYamlTypeConverter" /> of type <typeparam name="TYamlTypeConverter" />.
|
||||
/// </summary>
|
||||
public TBuilder WithoutTypeConverter<TYamlTypeConverter>()
|
||||
where TYamlTypeConverter : IYamlTypeConverter
|
||||
{
|
||||
return WithoutTypeConverter(typeof(TYamlTypeConverter));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing <see cref="IYamlTypeConverter" /> of type <param name="converterType" />.
|
||||
/// </summary>
|
||||
public TBuilder WithoutTypeConverter(Type converterType)
|
||||
{
|
||||
if (converterType == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(converterType));
|
||||
}
|
||||
|
||||
typeConverterFactories.Remove(converterType);
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="ITypeInspector" /> to be used by the (de)serializer.
|
||||
/// </summary>
|
||||
/// <param name="typeInspectorFactory">A function that instantiates the type inspector.</param>
|
||||
public TBuilder WithTypeInspector<TTypeInspector>(Func<ITypeInspector, TTypeInspector> typeInspectorFactory)
|
||||
where TTypeInspector : ITypeInspector
|
||||
{
|
||||
return WithTypeInspector(typeInspectorFactory, w => w.OnTop());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="ITypeInspector" /> to be used by the (de)serializer.
|
||||
/// </summary>
|
||||
/// <param name="typeInspectorFactory">A function that instantiates the type inspector.</param>
|
||||
/// <param name="where">Configures the location where to insert the <see cref="ITypeInspector" /></param>
|
||||
public TBuilder WithTypeInspector<TTypeInspector>(
|
||||
Func<ITypeInspector, TTypeInspector> typeInspectorFactory,
|
||||
Action<IRegistrationLocationSelectionSyntax<ITypeInspector>> where
|
||||
)
|
||||
where TTypeInspector : ITypeInspector
|
||||
{
|
||||
if (typeInspectorFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(typeInspectorFactory));
|
||||
}
|
||||
|
||||
if (where == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(where));
|
||||
}
|
||||
|
||||
where(typeInspectorFactories.CreateRegistrationLocationSelector(typeof(TTypeInspector), inner => typeInspectorFactory(inner)));
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="ITypeInspector" /> to be used by the (de)serializer.
|
||||
/// </summary>
|
||||
/// <param name="typeInspectorFactory">A function that instantiates the type inspector based on a previously registered <see cref="ITypeInspector" />..</param>
|
||||
/// <param name="where">Configures the location where to insert the <see cref="ITypeInspector" /></param>
|
||||
public TBuilder WithTypeInspector<TTypeInspector>(
|
||||
WrapperFactory<ITypeInspector, ITypeInspector, TTypeInspector> typeInspectorFactory,
|
||||
Action<ITrackingRegistrationLocationSelectionSyntax<ITypeInspector>> where
|
||||
)
|
||||
where TTypeInspector : ITypeInspector
|
||||
{
|
||||
if (typeInspectorFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(typeInspectorFactory));
|
||||
}
|
||||
|
||||
if (where == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(where));
|
||||
}
|
||||
|
||||
where(typeInspectorFactories.CreateTrackingRegistrationLocationSelector(typeof(TTypeInspector), (wrapped, inner) => typeInspectorFactory(wrapped, inner)));
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing <see cref="ITypeInspector" /> of type <typeparam name="TTypeInspector" />.
|
||||
/// </summary>
|
||||
public TBuilder WithoutTypeInspector<TTypeInspector>()
|
||||
where TTypeInspector : ITypeInspector
|
||||
{
|
||||
return WithoutTypeInspector(typeof(TTypeInspector));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing <see cref="ITypeInspector" /> of type <param name="inspectorType" />.
|
||||
/// </summary>
|
||||
public TBuilder WithoutTypeInspector(Type inspectorType)
|
||||
{
|
||||
if (inspectorType == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(inspectorType));
|
||||
}
|
||||
|
||||
typeInspectorFactories.Remove(inspectorType);
|
||||
return Self;
|
||||
}
|
||||
|
||||
protected IEnumerable<IYamlTypeConverter> BuildTypeConverters()
|
||||
{
|
||||
return typeConverterFactories.BuildComponentList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A factory that creates instances of <typeparamref name="TComponent" /> based on an existing <typeparamref name="TComponentBase" />.
|
||||
/// </summary>
|
||||
/// <typeparam name="TComponentBase">The type of the wrapped component.</typeparam>
|
||||
/// <typeparam name="TComponent">The type of the component that this factory creates.</typeparam>
|
||||
/// <param name="wrapped">The component that is to be wrapped.</param>
|
||||
/// <returns>Returns a new instance of <typeparamref name="TComponent" /> that is based on <paramref name="wrapped" />.</returns>
|
||||
public delegate TComponent WrapperFactory<TComponentBase, TComponent>(TComponentBase wrapped) where TComponent : TComponentBase;
|
||||
|
||||
/// <summary>
|
||||
/// A factory that creates instances of <typeparamref name="TComponent" /> based on an existing <typeparamref name="TComponentBase" /> and an argument.
|
||||
/// </summary>
|
||||
/// <typeparam name="TArgument">The type of the argument.</typeparam>
|
||||
/// <typeparam name="TComponentBase">The type of the wrapped component.</typeparam>
|
||||
/// <typeparam name="TComponent">The type of the component that this factory creates.</typeparam>
|
||||
/// <param name="wrapped">The component that is to be wrapped.</param>
|
||||
/// <param name="argument">The argument of the factory.</param>
|
||||
/// <returns>Returns a new instance of <typeparamref name="TComponent" /> that is based on <paramref name="wrapped" /> and <paramref name="argument" />.</returns>
|
||||
public delegate TComponent WrapperFactory<TArgument, TComponentBase, TComponent>(TComponentBase wrapped, TArgument argument) where TComponent : TComponentBase;
|
||||
}
|
||||
11
Assets/YamlDotNet/Serialization/BuilderSkeleton.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/BuilderSkeleton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d3f73aa22328f342ab53072ea83da7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/YamlDotNet/Serialization/Converters.meta
Normal file
9
Assets/YamlDotNet/Serialization/Converters.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 272f43609d820fd4aa820cc0636fe694
|
||||
folderAsset: yes
|
||||
timeCreated: 1427145262
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
115
Assets/YamlDotNet/Serialization/Converters/DateTimeConverter.cs
Normal file
115
Assets/YamlDotNet/Serialization/Converters/DateTimeConverter.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
// 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.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
|
||||
namespace YamlDotNet.Serialization.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// This represents the YAML converter entity for <see cref="DateTime"/>.
|
||||
/// </summary>
|
||||
public class DateTimeConverter : IYamlTypeConverter
|
||||
{
|
||||
private readonly DateTimeKind kind;
|
||||
private readonly IFormatProvider provider;
|
||||
private readonly string[] formats;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DateTimeConverter"/> class.
|
||||
/// </summary>
|
||||
/// <param name="kind"><see cref="DateTimeKind"/> value. Default value is <see cref="DateTimeKind.Utc"/>. <see cref="DateTimeKind.Unspecified"/> is considered as <see cref="DateTimeKind.Utc"/>.</param>
|
||||
/// <param name="provider"><see cref="IFormatProvider"/> instance. Default value is <see cref="CultureInfo.InvariantCulture"/>.</param>
|
||||
/// <param name="formats">List of date/time formats for parsing. Default value is "<c>G</c>".</param>
|
||||
/// <remarks>On deserializing, all formats in the list are used for conversion, while on serializing, the first format in the list is used.</remarks>
|
||||
public DateTimeConverter(DateTimeKind kind = DateTimeKind.Utc, IFormatProvider? provider = null, params string[] formats)
|
||||
{
|
||||
this.kind = kind == DateTimeKind.Unspecified ? DateTimeKind.Utc : kind;
|
||||
this.provider = provider ?? CultureInfo.InvariantCulture;
|
||||
this.formats = formats.DefaultIfEmpty("G").ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current converter supports converting the specified type.
|
||||
/// </summary>
|
||||
/// <param name="type"><see cref="Type"/> to check.</param>
|
||||
/// <returns>Returns <c>True</c>, if the current converter supports; otherwise returns <c>False</c>.</returns>
|
||||
public bool Accepts(Type type)
|
||||
{
|
||||
return type == typeof(DateTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an object's state from a YAML parser.
|
||||
/// </summary>
|
||||
/// <param name="parser"><see cref="IParser"/> instance.</param>
|
||||
/// <param name="type"><see cref="Type"/> to convert.</param>
|
||||
/// <returns>Returns the <see cref="DateTime"/> instance converted.</returns>
|
||||
/// <remarks>On deserializing, all formats in the list are used for conversion.</remarks>
|
||||
public object ReadYaml(IParser parser, Type type)
|
||||
{
|
||||
var value = parser.Consume<Scalar>().Value;
|
||||
var style = this.kind == DateTimeKind.Local ? DateTimeStyles.AssumeLocal : DateTimeStyles.AssumeUniversal;
|
||||
|
||||
var dt = DateTime.ParseExact(value, this.formats, this.provider, style);
|
||||
dt = EnsureDateTimeKind(dt, this.kind);
|
||||
return dt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified object's state to a YAML emitter.
|
||||
/// </summary>
|
||||
/// <param name="emitter"><see cref="IEmitter"/> instance.</param>
|
||||
/// <param name="value">Value to write.</param>
|
||||
/// <param name="type"><see cref="Type"/> to convert.</param>
|
||||
/// <remarks>On serializing, the first format in the list is used.</remarks>
|
||||
public void WriteYaml(IEmitter emitter, object? value, Type type)
|
||||
{
|
||||
var dt = (DateTime)value!;
|
||||
var adjusted = this.kind == DateTimeKind.Local ? dt.ToLocalTime() : dt.ToUniversalTime();
|
||||
var formatted = adjusted.ToString(this.formats.First(), this.provider); // Always take the first format of the list.
|
||||
|
||||
emitter.Emit(new Scalar(AnchorName.Empty, TagName.Empty, formatted, ScalarStyle.Any, true, false));
|
||||
}
|
||||
|
||||
private static DateTime EnsureDateTimeKind(DateTime dt, DateTimeKind kind)
|
||||
{
|
||||
DateTime ensured;
|
||||
if (dt.Kind == DateTimeKind.Local && kind == DateTimeKind.Utc)
|
||||
{
|
||||
ensured = dt.ToUniversalTime();
|
||||
return ensured;
|
||||
}
|
||||
|
||||
if (dt.Kind == DateTimeKind.Utc && kind == DateTimeKind.Local)
|
||||
{
|
||||
ensured = dt.ToLocalTime();
|
||||
return ensured;
|
||||
}
|
||||
|
||||
return dt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59f426f3754afee449a7e275b7a0c119
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/YamlDotNet/Serialization/Converters/GuidConverter.cs
Normal file
57
Assets/YamlDotNet/Serialization/Converters/GuidConverter.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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;
|
||||
using YamlDotNet.Core.Events;
|
||||
|
||||
namespace YamlDotNet.Serialization.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converter for System.Guid.
|
||||
/// </summary>
|
||||
public class GuidConverter : IYamlTypeConverter
|
||||
{
|
||||
private readonly bool jsonCompatible;
|
||||
|
||||
public GuidConverter(bool jsonCompatible)
|
||||
{
|
||||
this.jsonCompatible = jsonCompatible;
|
||||
}
|
||||
|
||||
public bool Accepts(Type type)
|
||||
{
|
||||
return type == typeof(Guid);
|
||||
}
|
||||
|
||||
public object ReadYaml(IParser parser, Type type)
|
||||
{
|
||||
var value = parser.Consume<Scalar>().Value;
|
||||
return new Guid(value);
|
||||
}
|
||||
|
||||
public void WriteYaml(IEmitter emitter, object? value, Type type)
|
||||
{
|
||||
var guid = (Guid)value!;
|
||||
emitter.Emit(new Scalar(AnchorName.Empty, TagName.Empty, guid.ToString("D"), jsonCompatible ? ScalarStyle.DoubleQuoted : ScalarStyle.Any, true, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2034b2a36cbe85a438addb075cff648b
|
||||
timeCreated: 1427145263
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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;
|
||||
using YamlDotNet.Core.Events;
|
||||
|
||||
namespace YamlDotNet.Serialization.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converter for System.Type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Converts <see cref="System.Type" /> to a scalar containing the assembly qualified name of the type.
|
||||
/// </remarks>
|
||||
public class SystemTypeConverter : IYamlTypeConverter
|
||||
{
|
||||
public bool Accepts(Type type)
|
||||
{
|
||||
return typeof(Type).IsAssignableFrom(type);
|
||||
}
|
||||
|
||||
public object ReadYaml(IParser parser, Type type)
|
||||
{
|
||||
var value = parser.Consume<Scalar>().Value;
|
||||
return Type.GetType(value, throwOnError: true)!; // Will throw instead of returning null
|
||||
}
|
||||
|
||||
public void WriteYaml(IEmitter emitter, object? value, Type type)
|
||||
{
|
||||
var systemType = (Type)value!;
|
||||
emitter.Emit(new Scalar(AnchorName.Empty, TagName.Empty, systemType.AssemblyQualifiedName!, ScalarStyle.Any, true, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb56a8270f28ae3438392cb2cfebe3b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
Assets/YamlDotNet/Serialization/DefaultValuesHandling.cs
Normal file
52
Assets/YamlDotNet/Serialization/DefaultValuesHandling.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the strategy to handle default and null values during serialization of properties.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum DefaultValuesHandling
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies that all properties are to be emitted regardless of their value. This is the default behavior.
|
||||
/// </summary>
|
||||
Preserve = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies that properties that contain null references or a null Nullable<T> are to be omitted.
|
||||
/// </summary>
|
||||
OmitNull = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies that properties that that contain their default value, either default(T) or the value specified in DefaultValueAttribute are to be omitted.
|
||||
/// </summary>
|
||||
OmitDefaults = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies that properties that that contain collections/arrays/enumerations that are empty are to be omitted.
|
||||
/// </summary>
|
||||
OmitEmptyCollections = 4,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16ab81ef49026d74abc0c7d9dd2addf1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
149
Assets/YamlDotNet/Serialization/Deserializer.cs
Normal file
149
Assets/YamlDotNet/Serialization/Deserializer.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
// 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.IO;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializes objects from the YAML format.
|
||||
/// To customize the behavior of <see cref="Deserializer" />,
|
||||
/// use the <see cref="DeserializerBuilder" /> class.
|
||||
/// </summary>
|
||||
public sealed class Deserializer : IDeserializer
|
||||
{
|
||||
private readonly IValueDeserializer valueDeserializer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="Deserializer" /> using the default configuration.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To customize the behavior of the deserializer, use <see cref="DeserializerBuilder" />.
|
||||
/// </remarks>
|
||||
public Deserializer()
|
||||
: this(new DeserializerBuilder().BuildValueDeserializer())
|
||||
{
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// This constructor is private to discourage its use.
|
||||
/// To invoke it, call the <see cref="FromValueDeserializer"/> method.
|
||||
/// </remarks>
|
||||
private Deserializer(IValueDeserializer valueDeserializer)
|
||||
{
|
||||
this.valueDeserializer = valueDeserializer ?? throw new ArgumentNullException(nameof(valueDeserializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Deserializer" /> that uses the specified <see cref="IValueDeserializer" />.
|
||||
/// This method is available for advanced scenarios. The preferred way to customize the behavior of the
|
||||
/// deserializer is to use <see cref="DeserializerBuilder" />.
|
||||
/// </summary>
|
||||
public static Deserializer FromValueDeserializer(IValueDeserializer valueDeserializer)
|
||||
{
|
||||
return new Deserializer(valueDeserializer);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(string input)
|
||||
{
|
||||
using var reader = new StringReader(input);
|
||||
return Deserialize<T>(reader);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(TextReader input)
|
||||
{
|
||||
return Deserialize<T>(new Parser(input));
|
||||
}
|
||||
|
||||
public object? Deserialize(TextReader input)
|
||||
{
|
||||
return Deserialize(input, typeof(object));
|
||||
}
|
||||
|
||||
public object? Deserialize(string input, Type type)
|
||||
{
|
||||
using var reader = new StringReader(input);
|
||||
return Deserialize(reader, type);
|
||||
}
|
||||
|
||||
public object? Deserialize(TextReader input, Type type)
|
||||
{
|
||||
return Deserialize(new Parser(input), type);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(IParser parser)
|
||||
{
|
||||
return (T)Deserialize(parser, typeof(T))!; // We really want an exception if we are trying to deserialize null into a non-nullable type
|
||||
}
|
||||
|
||||
public object? Deserialize(IParser parser)
|
||||
{
|
||||
return Deserialize(parser, typeof(object));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes an object of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="parser">The <see cref="IParser" /> from where to deserialize the object.</param>
|
||||
/// <param name="type">The static type of the object to deserialize.</param>
|
||||
/// <returns>Returns the deserialized object.</returns>
|
||||
public object? Deserialize(IParser parser, Type type)
|
||||
{
|
||||
if (parser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parser));
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
var hasStreamStart = parser.TryConsume<StreamStart>(out var _);
|
||||
|
||||
var hasDocumentStart = parser.TryConsume<DocumentStart>(out var _);
|
||||
|
||||
object? result = null;
|
||||
if (!parser.Accept<DocumentEnd>(out var _) && !parser.Accept<StreamEnd>(out var _))
|
||||
{
|
||||
using var state = new SerializerState();
|
||||
result = valueDeserializer.DeserializeValue(parser, type, state, valueDeserializer);
|
||||
state.OnDeserialization();
|
||||
}
|
||||
|
||||
if (hasDocumentStart)
|
||||
{
|
||||
parser.Consume<DocumentEnd>();
|
||||
}
|
||||
|
||||
if (hasStreamStart)
|
||||
{
|
||||
parser.Consume<StreamEnd>();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/YamlDotNet/Serialization/Deserializer.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/Deserializer.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cee7b8e2c23b44c4c9d8b6fa9029e350
|
||||
timeCreated: 1427145266
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
389
Assets/YamlDotNet/Serialization/DeserializerBuilder.cs
Normal file
389
Assets/YamlDotNet/Serialization/DeserializerBuilder.cs
Normal file
@@ -0,0 +1,389 @@
|
||||
// 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;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
using YamlDotNet.Serialization.NodeDeserializers;
|
||||
using YamlDotNet.Serialization.NodeTypeResolvers;
|
||||
using YamlDotNet.Serialization.ObjectFactories;
|
||||
using YamlDotNet.Serialization.Schemas;
|
||||
using YamlDotNet.Serialization.TypeInspectors;
|
||||
using YamlDotNet.Serialization.TypeResolvers;
|
||||
using YamlDotNet.Serialization.ValueDeserializers;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates and configures instances of <see cref="Deserializer" />.
|
||||
/// This class is used to customize the behavior of <see cref="Deserializer" />. Use the relevant methods
|
||||
/// to apply customizations, then call <see cref="Build" /> to create an instance of the deserializer
|
||||
/// with the desired customizations.
|
||||
/// </summary>
|
||||
public sealed class DeserializerBuilder : BuilderSkeleton<DeserializerBuilder>
|
||||
{
|
||||
private Lazy<IObjectFactory> objectFactory;
|
||||
private readonly LazyComponentRegistrationList<Nothing, INodeDeserializer> nodeDeserializerFactories;
|
||||
private readonly LazyComponentRegistrationList<Nothing, INodeTypeResolver> nodeTypeResolverFactories;
|
||||
private readonly Dictionary<TagName, Type> tagMappings;
|
||||
private readonly Dictionary<Type, Type> typeMappings;
|
||||
private bool ignoreUnmatched;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="DeserializerBuilder" /> using the default component registrations.
|
||||
/// </summary>
|
||||
public DeserializerBuilder()
|
||||
: base(new StaticTypeResolver())
|
||||
{
|
||||
typeMappings = new Dictionary<Type, Type>();
|
||||
objectFactory = new Lazy<IObjectFactory>(() => new DefaultObjectFactory(typeMappings), true);
|
||||
|
||||
tagMappings = new Dictionary<TagName, Type>
|
||||
{
|
||||
{ FailsafeSchema.Tags.Map, typeof(Dictionary<object, object>) },
|
||||
{ FailsafeSchema.Tags.Str, typeof(string) },
|
||||
{ JsonSchema.Tags.Bool, typeof(bool) },
|
||||
{ JsonSchema.Tags.Float, typeof(double) },
|
||||
{ JsonSchema.Tags.Int, typeof(int) },
|
||||
{ DefaultSchema.Tags.Timestamp, typeof(DateTime) }
|
||||
};
|
||||
|
||||
typeInspectorFactories.Add(typeof(CachedTypeInspector), inner => new CachedTypeInspector(inner));
|
||||
typeInspectorFactories.Add(typeof(NamingConventionTypeInspector), inner => namingConvention is NullNamingConvention ? inner : new NamingConventionTypeInspector(inner, namingConvention));
|
||||
typeInspectorFactories.Add(typeof(YamlAttributesTypeInspector), inner => new YamlAttributesTypeInspector(inner));
|
||||
typeInspectorFactories.Add(typeof(YamlAttributeOverridesInspector), inner => overrides != null ? new YamlAttributeOverridesInspector(inner, overrides.Clone()) : inner);
|
||||
typeInspectorFactories.Add(typeof(ReadableAndWritablePropertiesTypeInspector), inner => new ReadableAndWritablePropertiesTypeInspector(inner));
|
||||
|
||||
nodeDeserializerFactories = new LazyComponentRegistrationList<Nothing, INodeDeserializer>
|
||||
{
|
||||
{ typeof(YamlConvertibleNodeDeserializer), _ => new YamlConvertibleNodeDeserializer(objectFactory.Value) },
|
||||
{ typeof(YamlSerializableNodeDeserializer), _ => new YamlSerializableNodeDeserializer(objectFactory.Value) },
|
||||
{ typeof(TypeConverterNodeDeserializer), _ => new TypeConverterNodeDeserializer(BuildTypeConverters()) },
|
||||
{ typeof(NullNodeDeserializer), _ => new NullNodeDeserializer() },
|
||||
{ typeof(ScalarNodeDeserializer), _ => new ScalarNodeDeserializer() },
|
||||
{ typeof(ArrayNodeDeserializer), _ => new ArrayNodeDeserializer() },
|
||||
{ typeof(DictionaryNodeDeserializer), _ => new DictionaryNodeDeserializer(objectFactory.Value) },
|
||||
{ typeof(CollectionNodeDeserializer), _ => new CollectionNodeDeserializer(objectFactory.Value) },
|
||||
{ typeof(EnumerableNodeDeserializer), _ => new EnumerableNodeDeserializer() },
|
||||
{ typeof(ObjectNodeDeserializer), _ => new ObjectNodeDeserializer(objectFactory.Value, BuildTypeInspector(), ignoreUnmatched) }
|
||||
};
|
||||
|
||||
nodeTypeResolverFactories = new LazyComponentRegistrationList<Nothing, INodeTypeResolver>
|
||||
{
|
||||
{ typeof(MappingNodeTypeResolver), _ => new MappingNodeTypeResolver(typeMappings) },
|
||||
{ typeof(YamlConvertibleTypeResolver), _ => new YamlConvertibleTypeResolver() },
|
||||
{ typeof(YamlSerializableTypeResolver), _ => new YamlSerializableTypeResolver() },
|
||||
{ typeof(TagNodeTypeResolver), _ => new TagNodeTypeResolver(tagMappings) },
|
||||
{ typeof(PreventUnknownTagsNodeTypeResolver), _ => new PreventUnknownTagsNodeTypeResolver() },
|
||||
{ typeof(DefaultContainersNodeTypeResolver), _ => new DefaultContainersNodeTypeResolver() }
|
||||
};
|
||||
}
|
||||
|
||||
protected override DeserializerBuilder Self { get { return this; } }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IObjectFactory" /> that will be used by the deserializer.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithObjectFactory(IObjectFactory objectFactory)
|
||||
{
|
||||
if (objectFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(objectFactory));
|
||||
}
|
||||
|
||||
this.objectFactory = new Lazy<IObjectFactory>(() => objectFactory, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IObjectFactory" /> that will be used by the deserializer.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithObjectFactory(Func<Type, object> objectFactory)
|
||||
{
|
||||
if (objectFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(objectFactory));
|
||||
}
|
||||
|
||||
return WithObjectFactory(new LambdaObjectFactory(objectFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="INodeDeserializer" /> to be used by the deserializer.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithNodeDeserializer(INodeDeserializer nodeDeserializer)
|
||||
{
|
||||
return WithNodeDeserializer(nodeDeserializer, w => w.OnTop());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="INodeDeserializer" /> to be used by the deserializer.
|
||||
/// </summary>
|
||||
/// <param name="nodeDeserializer"></param>
|
||||
/// <param name="where">Configures the location where to insert the <see cref="INodeDeserializer" /></param>
|
||||
public DeserializerBuilder WithNodeDeserializer(
|
||||
INodeDeserializer nodeDeserializer,
|
||||
Action<IRegistrationLocationSelectionSyntax<INodeDeserializer>> where
|
||||
)
|
||||
{
|
||||
if (nodeDeserializer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodeDeserializer));
|
||||
}
|
||||
|
||||
if (where == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(where));
|
||||
}
|
||||
|
||||
where(nodeDeserializerFactories.CreateRegistrationLocationSelector(nodeDeserializer.GetType(), _ => nodeDeserializer));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="INodeDeserializer" /> to be used by the deserializer.
|
||||
/// </summary>
|
||||
/// <param name="nodeDeserializerFactory">A factory that creates the <see cref="INodeDeserializer" /> based on a previously registered <see cref="INodeDeserializer" />.</param>
|
||||
/// <param name="where">Configures the location where to insert the <see cref="INodeDeserializer" /></param>
|
||||
public DeserializerBuilder WithNodeDeserializer<TNodeDeserializer>(
|
||||
WrapperFactory<INodeDeserializer, TNodeDeserializer> nodeDeserializerFactory,
|
||||
Action<ITrackingRegistrationLocationSelectionSyntax<INodeDeserializer>> where
|
||||
)
|
||||
where TNodeDeserializer : INodeDeserializer
|
||||
{
|
||||
if (nodeDeserializerFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodeDeserializerFactory));
|
||||
}
|
||||
|
||||
if (where == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(where));
|
||||
}
|
||||
|
||||
where(nodeDeserializerFactories.CreateTrackingRegistrationLocationSelector(typeof(TNodeDeserializer), (wrapped, _) => nodeDeserializerFactory(wrapped)));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing <see cref="INodeDeserializer" /> of type <typeparam name="TNodeDeserializer" />.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithoutNodeDeserializer<TNodeDeserializer>()
|
||||
where TNodeDeserializer : INodeDeserializer
|
||||
{
|
||||
return WithoutNodeDeserializer(typeof(TNodeDeserializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing <see cref="INodeDeserializer" /> of type <param name="nodeDeserializerType" />.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithoutNodeDeserializer(Type nodeDeserializerType)
|
||||
{
|
||||
if (nodeDeserializerType == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodeDeserializerType));
|
||||
}
|
||||
|
||||
nodeDeserializerFactories.Remove(nodeDeserializerType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="INodeTypeResolver" /> to be used by the deserializer.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithNodeTypeResolver(INodeTypeResolver nodeTypeResolver)
|
||||
{
|
||||
return WithNodeTypeResolver(nodeTypeResolver, w => w.OnTop());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="INodeTypeResolver" /> to be used by the deserializer.
|
||||
/// </summary>
|
||||
/// <param name="nodeTypeResolver"></param>
|
||||
/// <param name="where">Configures the location where to insert the <see cref="INodeTypeResolver" /></param>
|
||||
public DeserializerBuilder WithNodeTypeResolver(
|
||||
INodeTypeResolver nodeTypeResolver,
|
||||
Action<IRegistrationLocationSelectionSyntax<INodeTypeResolver>> where
|
||||
)
|
||||
{
|
||||
if (nodeTypeResolver == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodeTypeResolver));
|
||||
}
|
||||
|
||||
if (where == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(where));
|
||||
}
|
||||
|
||||
where(nodeTypeResolverFactories.CreateRegistrationLocationSelector(nodeTypeResolver.GetType(), _ => nodeTypeResolver));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers an additional <see cref="INodeTypeResolver" /> to be used by the deserializer.
|
||||
/// </summary>
|
||||
/// <param name="nodeTypeResolverFactory">A factory that creates the <see cref="INodeTypeResolver" /> based on a previously registered <see cref="INodeTypeResolver" />.</param>
|
||||
/// <param name="where">Configures the location where to insert the <see cref="INodeTypeResolver" /></param>
|
||||
public DeserializerBuilder WithNodeTypeResolver<TNodeTypeResolver>(
|
||||
WrapperFactory<INodeTypeResolver, TNodeTypeResolver> nodeTypeResolverFactory,
|
||||
Action<ITrackingRegistrationLocationSelectionSyntax<INodeTypeResolver>> where
|
||||
)
|
||||
where TNodeTypeResolver : INodeTypeResolver
|
||||
{
|
||||
if (nodeTypeResolverFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodeTypeResolverFactory));
|
||||
}
|
||||
|
||||
if (where == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(where));
|
||||
}
|
||||
|
||||
where(nodeTypeResolverFactories.CreateTrackingRegistrationLocationSelector(typeof(TNodeTypeResolver), (wrapped, _) => nodeTypeResolverFactory(wrapped)));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing <see cref="INodeTypeResolver" /> of type <typeparam name="TNodeTypeResolver" />.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithoutNodeTypeResolver<TNodeTypeResolver>()
|
||||
where TNodeTypeResolver : INodeTypeResolver
|
||||
{
|
||||
return WithoutNodeTypeResolver(typeof(TNodeTypeResolver));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing <see cref="INodeTypeResolver" /> of type <param name="nodeTypeResolverType" />.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithoutNodeTypeResolver(Type nodeTypeResolverType)
|
||||
{
|
||||
if (nodeTypeResolverType == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nodeTypeResolverType));
|
||||
}
|
||||
|
||||
nodeTypeResolverFactories.Remove(nodeTypeResolverType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a tag mapping.
|
||||
/// </summary>
|
||||
public override DeserializerBuilder WithTagMapping(TagName tag, Type type)
|
||||
{
|
||||
if (tag.IsEmpty)
|
||||
{
|
||||
throw new ArgumentException("Non-specific tags cannot be maped");
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
if (tagMappings.TryGetValue(tag, out var alreadyRegisteredType))
|
||||
{
|
||||
throw new ArgumentException($"Type already has a registered type '{alreadyRegisteredType.FullName}' for tag '{tag}'", nameof(tag));
|
||||
}
|
||||
|
||||
tagMappings.Add(tag, type);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a type mapping using the default object factory.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithTypeMapping<TInterface, TConcrete>()
|
||||
where TConcrete : TInterface
|
||||
{
|
||||
var interfaceType = typeof(TInterface);
|
||||
var concreteType = typeof(TConcrete);
|
||||
|
||||
if (!interfaceType.IsAssignableFrom(concreteType))
|
||||
{
|
||||
throw new InvalidOperationException($"The type '{concreteType.Name}' does not implement interface '{interfaceType.Name}'.");
|
||||
}
|
||||
|
||||
if (typeMappings.ContainsKey(interfaceType))
|
||||
{
|
||||
typeMappings[interfaceType] = concreteType;
|
||||
}
|
||||
else
|
||||
{
|
||||
typeMappings.Add(interfaceType, concreteType);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters an existing tag mapping.
|
||||
/// </summary>
|
||||
public DeserializerBuilder WithoutTagMapping(TagName tag)
|
||||
{
|
||||
if (tag.IsEmpty)
|
||||
{
|
||||
throw new ArgumentException("Non-specific tags cannot be maped");
|
||||
}
|
||||
|
||||
if (!tagMappings.Remove(tag))
|
||||
{
|
||||
throw new KeyNotFoundException($"Tag '{tag}' is not registered");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instructs the deserializer to ignore unmatched properties instead of throwing an exception.
|
||||
/// </summary>
|
||||
public DeserializerBuilder IgnoreUnmatchedProperties()
|
||||
{
|
||||
ignoreUnmatched = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Deserializer" /> according to the current configuration.
|
||||
/// </summary>
|
||||
public IDeserializer Build()
|
||||
{
|
||||
return Deserializer.FromValueDeserializer(BuildValueDeserializer());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="IValueDeserializer" /> that implements the current configuration.
|
||||
/// This method is available for advanced scenarios. The preferred way to customize the behavior of the
|
||||
/// deserializer is to use the <see cref="Build" /> method.
|
||||
/// </summary>
|
||||
public IValueDeserializer BuildValueDeserializer()
|
||||
{
|
||||
return new AliasValueDeserializer(
|
||||
new NodeValueDeserializer(
|
||||
nodeDeserializerFactories.BuildComponentList(),
|
||||
nodeTypeResolverFactories.BuildComponentList()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/YamlDotNet/Serialization/DeserializerBuilder.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/DeserializerBuilder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ef2383a78598ce4b921ed59f9cbbceb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,82 @@
|
||||
// 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;
|
||||
using YamlDotNet.Core;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
public sealed class EmissionPhaseObjectGraphVisitorArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the next visitor that should be called by the current visitor.
|
||||
/// </summary>
|
||||
public IObjectGraphVisitor<IEmitter> InnerVisitor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IEventEmitter" /> that is to be used for serialization.
|
||||
/// </summary>
|
||||
public IEventEmitter EventEmitter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a function that, when called, serializes the specified object.
|
||||
/// </summary>
|
||||
public ObjectSerializer NestedObjectSerializer { get; private set; }
|
||||
|
||||
public IEnumerable<IYamlTypeConverter> TypeConverters { get; private set; }
|
||||
|
||||
private readonly IEnumerable<IObjectGraphVisitor<Nothing>> preProcessingPhaseVisitors;
|
||||
|
||||
public EmissionPhaseObjectGraphVisitorArgs(
|
||||
IObjectGraphVisitor<IEmitter> innerVisitor,
|
||||
IEventEmitter eventEmitter,
|
||||
IEnumerable<IObjectGraphVisitor<Nothing>> preProcessingPhaseVisitors,
|
||||
IEnumerable<IYamlTypeConverter> typeConverters,
|
||||
ObjectSerializer nestedObjectSerializer
|
||||
)
|
||||
{
|
||||
InnerVisitor = innerVisitor ?? throw new ArgumentNullException(nameof(innerVisitor));
|
||||
EventEmitter = eventEmitter ?? throw new ArgumentNullException(nameof(eventEmitter));
|
||||
this.preProcessingPhaseVisitors = preProcessingPhaseVisitors ?? throw new ArgumentNullException(nameof(preProcessingPhaseVisitors));
|
||||
TypeConverters = typeConverters ?? throw new ArgumentNullException(nameof(typeConverters));
|
||||
NestedObjectSerializer = nestedObjectSerializer ?? throw new ArgumentNullException(nameof(nestedObjectSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the visitor of type <typeparamref name="T" /> that was used during the pre-processing phase.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the visitor.s</typeparam>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// No visitor of that type has been registered,
|
||||
/// or ore than one visitors registered are of type <typeparamref name="T"/>.
|
||||
/// </exception>
|
||||
public T GetPreProcessingPhaseObjectGraphVisitor<T>()
|
||||
where T : IObjectGraphVisitor<Nothing>
|
||||
{
|
||||
return preProcessingPhaseVisitors
|
||||
.OfType<T>()
|
||||
.Single();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2a250c3185b3314da07c8ab685d5325
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/YamlDotNet/Serialization/EventEmitters.meta
Normal file
9
Assets/YamlDotNet/Serialization/EventEmitters.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9ef080653208014a9cc235469180344
|
||||
folderAsset: yes
|
||||
timeCreated: 1427145262
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
// 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.EventEmitters
|
||||
{
|
||||
/// <summary>
|
||||
/// Provided the base implementation for an IEventEmitter that is a
|
||||
/// decorator for another IEventEmitter.
|
||||
/// </summary>
|
||||
public abstract class ChainedEventEmitter : IEventEmitter
|
||||
{
|
||||
protected readonly IEventEmitter nextEmitter;
|
||||
|
||||
protected ChainedEventEmitter(IEventEmitter nextEmitter)
|
||||
{
|
||||
this.nextEmitter = nextEmitter ?? throw new ArgumentNullException(nameof(nextEmitter));
|
||||
}
|
||||
|
||||
public virtual void Emit(AliasEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
nextEmitter.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public virtual void Emit(ScalarEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
nextEmitter.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public virtual void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
nextEmitter.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public virtual void Emit(MappingEndEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
nextEmitter.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public virtual void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
nextEmitter.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public virtual void Emit(SequenceEndEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
nextEmitter.Emit(eventInfo, emitter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccb97ea0d5b5aff4d93a807363ef3ec7
|
||||
timeCreated: 1427145266
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,126 @@
|
||||
// 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;
|
||||
using YamlDotNet.Core.Events;
|
||||
|
||||
namespace YamlDotNet.Serialization.EventEmitters
|
||||
{
|
||||
public sealed class JsonEventEmitter : ChainedEventEmitter
|
||||
{
|
||||
public JsonEventEmitter(IEventEmitter nextEmitter)
|
||||
: base(nextEmitter)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Emit(AliasEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
eventInfo.NeedsExpansion = true;
|
||||
}
|
||||
|
||||
public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
eventInfo.IsPlainImplicit = true;
|
||||
eventInfo.Style = ScalarStyle.Plain;
|
||||
|
||||
var value = eventInfo.Source.Value;
|
||||
if (value == null)
|
||||
{
|
||||
eventInfo.RenderedValue = "null";
|
||||
}
|
||||
else
|
||||
{
|
||||
var typeCode = eventInfo.Source.Type.GetTypeCode();
|
||||
switch (typeCode)
|
||||
{
|
||||
case TypeCode.Boolean:
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatBoolean(value);
|
||||
break;
|
||||
|
||||
case TypeCode.Byte:
|
||||
case TypeCode.Int16:
|
||||
case TypeCode.Int32:
|
||||
case TypeCode.Int64:
|
||||
case TypeCode.SByte:
|
||||
case TypeCode.UInt16:
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.UInt64:
|
||||
var valueIsEnum = eventInfo.Source.Type.IsEnum();
|
||||
if (valueIsEnum)
|
||||
{
|
||||
eventInfo.RenderedValue = value.ToString()!;
|
||||
eventInfo.Style = ScalarStyle.DoubleQuoted;
|
||||
break;
|
||||
}
|
||||
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatNumber(value);
|
||||
break;
|
||||
|
||||
case TypeCode.Single:
|
||||
case TypeCode.Double:
|
||||
case TypeCode.Decimal:
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatNumber(value);
|
||||
break;
|
||||
|
||||
case TypeCode.String:
|
||||
case TypeCode.Char:
|
||||
eventInfo.RenderedValue = value.ToString()!;
|
||||
eventInfo.Style = ScalarStyle.DoubleQuoted;
|
||||
break;
|
||||
|
||||
case TypeCode.DateTime:
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatDateTime(value);
|
||||
break;
|
||||
|
||||
case TypeCode.Empty:
|
||||
eventInfo.RenderedValue = "null";
|
||||
break;
|
||||
|
||||
default:
|
||||
if (eventInfo.Source.Type == typeof(TimeSpan))
|
||||
{
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatTimeSpan(value);
|
||||
break;
|
||||
}
|
||||
|
||||
throw new NotSupportedException($"TypeCode.{typeCode} is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
base.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public override void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
eventInfo.Style = MappingStyle.Flow;
|
||||
|
||||
base.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public override void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
eventInfo.Style = SequenceStyle.Flow;
|
||||
|
||||
base.Emit(eventInfo, emitter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62580a3e5f0e5314e83b62758257428e
|
||||
timeCreated: 1427495771
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,155 @@
|
||||
// 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;
|
||||
using YamlDotNet.Serialization.Schemas;
|
||||
|
||||
namespace YamlDotNet.Serialization.EventEmitters
|
||||
{
|
||||
public sealed class TypeAssigningEventEmitter : ChainedEventEmitter
|
||||
{
|
||||
private readonly bool requireTagWhenStaticAndActualTypesAreDifferent;
|
||||
private readonly IDictionary<Type, TagName> tagMappings;
|
||||
|
||||
public TypeAssigningEventEmitter(IEventEmitter nextEmitter, bool requireTagWhenStaticAndActualTypesAreDifferent, IDictionary<Type, TagName> tagMappings)
|
||||
: base(nextEmitter)
|
||||
{
|
||||
this.requireTagWhenStaticAndActualTypesAreDifferent = requireTagWhenStaticAndActualTypesAreDifferent;
|
||||
this.tagMappings = tagMappings ?? throw new ArgumentNullException(nameof(tagMappings));
|
||||
}
|
||||
|
||||
public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
var suggestedStyle = ScalarStyle.Plain;
|
||||
|
||||
var value = eventInfo.Source.Value;
|
||||
if (value == null)
|
||||
{
|
||||
eventInfo.Tag = JsonSchema.Tags.Null;
|
||||
eventInfo.RenderedValue = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
var typeCode = eventInfo.Source.Type.GetTypeCode();
|
||||
switch (typeCode)
|
||||
{
|
||||
case TypeCode.Boolean:
|
||||
eventInfo.Tag = JsonSchema.Tags.Bool;
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatBoolean(value);
|
||||
break;
|
||||
|
||||
case TypeCode.Byte:
|
||||
case TypeCode.Int16:
|
||||
case TypeCode.Int32:
|
||||
case TypeCode.Int64:
|
||||
case TypeCode.SByte:
|
||||
case TypeCode.UInt16:
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.UInt64:
|
||||
eventInfo.Tag = JsonSchema.Tags.Int;
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatNumber(value);
|
||||
break;
|
||||
|
||||
case TypeCode.Single:
|
||||
eventInfo.Tag = JsonSchema.Tags.Float;
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatNumber((float)value);
|
||||
break;
|
||||
|
||||
case TypeCode.Double:
|
||||
eventInfo.Tag = JsonSchema.Tags.Float;
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatNumber((double)value);
|
||||
break;
|
||||
|
||||
case TypeCode.Decimal:
|
||||
eventInfo.Tag = JsonSchema.Tags.Float;
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatNumber(value);
|
||||
break;
|
||||
|
||||
case TypeCode.String:
|
||||
case TypeCode.Char:
|
||||
eventInfo.Tag = FailsafeSchema.Tags.Str;
|
||||
eventInfo.RenderedValue = value.ToString()!;
|
||||
suggestedStyle = ScalarStyle.Any;
|
||||
break;
|
||||
|
||||
case TypeCode.DateTime:
|
||||
eventInfo.Tag = DefaultSchema.Tags.Timestamp;
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatDateTime(value);
|
||||
break;
|
||||
|
||||
case TypeCode.Empty:
|
||||
eventInfo.Tag = JsonSchema.Tags.Null;
|
||||
eventInfo.RenderedValue = "";
|
||||
break;
|
||||
|
||||
default:
|
||||
if (eventInfo.Source.Type == typeof(TimeSpan))
|
||||
{
|
||||
eventInfo.RenderedValue = YamlFormatter.FormatTimeSpan(value);
|
||||
break;
|
||||
}
|
||||
|
||||
throw new NotSupportedException($"TypeCode.{typeCode} is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
eventInfo.IsPlainImplicit = true;
|
||||
if (eventInfo.Style == ScalarStyle.Any)
|
||||
{
|
||||
eventInfo.Style = suggestedStyle;
|
||||
}
|
||||
|
||||
base.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public override void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
AssignTypeIfNeeded(eventInfo);
|
||||
base.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public override void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
AssignTypeIfNeeded(eventInfo);
|
||||
base.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
private void AssignTypeIfNeeded(ObjectEventInfo eventInfo)
|
||||
{
|
||||
if (tagMappings.TryGetValue(eventInfo.Source.Type, out var tag))
|
||||
{
|
||||
eventInfo.Tag = tag;
|
||||
}
|
||||
else if (requireTagWhenStaticAndActualTypesAreDifferent && eventInfo.Source.Value != null && eventInfo.Source.Type != eventInfo.Source.StaticType)
|
||||
{
|
||||
throw new YamlException(
|
||||
$"Cannot serialize type '{eventInfo.Source.Type.FullName}' where a '{eventInfo.Source.StaticType.FullName}' was expected "
|
||||
+ $"because no tag mapping has been registered for '{eventInfo.Source.Type.FullName}', "
|
||||
+ $"which means that it won't be possible to deserialize the document.\n"
|
||||
+ $"Register a tag mapping using the SerializerBuilder.WithTagMapping method.\n\n"
|
||||
+ $"E.g: builder.WithTagMapping(\"!{eventInfo.Source.Type.Name}\", typeof({eventInfo.Source.Type.FullName}));"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1b82bb57f4eb7f4ba0ffad467f82555
|
||||
timeCreated: 1427145266
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
// 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;
|
||||
using YamlDotNet.Core.Events;
|
||||
|
||||
namespace YamlDotNet.Serialization.EventEmitters
|
||||
{
|
||||
public sealed class WriterEventEmitter : IEventEmitter
|
||||
{
|
||||
void IEventEmitter.Emit(AliasEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
emitter.Emit(new AnchorAlias(eventInfo.Alias));
|
||||
}
|
||||
|
||||
void IEventEmitter.Emit(ScalarEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
emitter.Emit(new Scalar(eventInfo.Anchor, eventInfo.Tag, eventInfo.RenderedValue, eventInfo.Style, eventInfo.IsPlainImplicit, eventInfo.IsQuotedImplicit));
|
||||
}
|
||||
|
||||
void IEventEmitter.Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
emitter.Emit(new MappingStart(eventInfo.Anchor, eventInfo.Tag, eventInfo.IsImplicit, eventInfo.Style));
|
||||
}
|
||||
|
||||
void IEventEmitter.Emit(MappingEndEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
emitter.Emit(new MappingEnd());
|
||||
}
|
||||
|
||||
void IEventEmitter.Emit(SequenceStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
emitter.Emit(new SequenceStart(eventInfo.Anchor, eventInfo.Tag, eventInfo.IsImplicit, eventInfo.Style));
|
||||
}
|
||||
|
||||
void IEventEmitter.Emit(SequenceEndEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
emitter.Emit(new SequenceEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2ea019325fb629499443d6af969a295
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
117
Assets/YamlDotNet/Serialization/EventInfo.cs
Normal file
117
Assets/YamlDotNet/Serialization/EventInfo.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
// 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;
|
||||
using YamlDotNet.Core.Events;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
public abstract class EventInfo
|
||||
{
|
||||
public IObjectDescriptor Source { get; }
|
||||
|
||||
protected EventInfo(IObjectDescriptor source)
|
||||
{
|
||||
Source = source ?? throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
}
|
||||
|
||||
public class AliasEventInfo : EventInfo
|
||||
{
|
||||
public AliasEventInfo(IObjectDescriptor source, AnchorName alias)
|
||||
: base(source)
|
||||
{
|
||||
if (alias.IsEmpty)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(alias));
|
||||
}
|
||||
Alias = alias;
|
||||
}
|
||||
|
||||
public AnchorName Alias { get; }
|
||||
public bool NeedsExpansion { get; set; }
|
||||
}
|
||||
|
||||
public class ObjectEventInfo : EventInfo
|
||||
{
|
||||
protected ObjectEventInfo(IObjectDescriptor source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
public AnchorName Anchor { get; set; }
|
||||
public TagName Tag { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ScalarEventInfo : ObjectEventInfo
|
||||
{
|
||||
public ScalarEventInfo(IObjectDescriptor source)
|
||||
: base(source)
|
||||
{
|
||||
Style = source.ScalarStyle;
|
||||
RenderedValue = string.Empty;
|
||||
}
|
||||
|
||||
public string RenderedValue { get; set; }
|
||||
public ScalarStyle Style { get; set; }
|
||||
public bool IsPlainImplicit { get; set; }
|
||||
public bool IsQuotedImplicit { get; set; }
|
||||
}
|
||||
|
||||
public sealed class MappingStartEventInfo : ObjectEventInfo
|
||||
{
|
||||
public MappingStartEventInfo(IObjectDescriptor source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsImplicit { get; set; }
|
||||
public MappingStyle Style { get; set; }
|
||||
}
|
||||
|
||||
public sealed class MappingEndEventInfo : EventInfo
|
||||
{
|
||||
public MappingEndEventInfo(IObjectDescriptor source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SequenceStartEventInfo : ObjectEventInfo
|
||||
{
|
||||
public SequenceStartEventInfo(IObjectDescriptor source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsImplicit { get; set; }
|
||||
public SequenceStyle Style { get; set; }
|
||||
}
|
||||
|
||||
public sealed class SequenceEndEventInfo : EventInfo
|
||||
{
|
||||
public SequenceEndEventInfo(IObjectDescriptor source)
|
||||
: base(source)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/YamlDotNet/Serialization/EventInfo.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/EventInfo.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e72f96c4049a0dc4d97ad0d44f6b766d
|
||||
timeCreated: 1427145267
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/YamlDotNet/Serialization/IAliasProvider.cs
Normal file
30
Assets/YamlDotNet/Serialization/IAliasProvider.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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
|
||||
{
|
||||
public interface IAliasProvider
|
||||
{
|
||||
AnchorName GetAlias(object target);
|
||||
}
|
||||
}
|
||||
12
Assets/YamlDotNet/Serialization/IAliasProvider.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/IAliasProvider.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a934679d1d7f204e9d25f18f7f397bb
|
||||
timeCreated: 1427145263
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/YamlDotNet/Serialization/IDeserializer.cs
Normal file
46
Assets/YamlDotNet/Serialization/IDeserializer.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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.IO;
|
||||
using YamlDotNet.Core;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
public interface IDeserializer
|
||||
{
|
||||
T Deserialize<T>(string input);
|
||||
T Deserialize<T>(TextReader input);
|
||||
object? Deserialize(TextReader input);
|
||||
object? Deserialize(string input, Type type);
|
||||
object? Deserialize(TextReader input, Type type);
|
||||
T Deserialize<T>(IParser parser);
|
||||
object? Deserialize(IParser parser);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes an object of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="parser">The <see cref="IParser" /> from where to deserialize the object.</param>
|
||||
/// <param name="type">The static type of the object to deserialize.</param>
|
||||
/// <returns>Returns the deserialized object.</returns>
|
||||
object? Deserialize(IParser parser, Type type);
|
||||
}
|
||||
}
|
||||
11
Assets/YamlDotNet/Serialization/IDeserializer.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/IDeserializer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4ca32ff329536b43a4ba3711e5af24e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/YamlDotNet/Serialization/IEventEmitter.cs
Normal file
35
Assets/YamlDotNet/Serialization/IEventEmitter.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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
|
||||
{
|
||||
public interface IEventEmitter
|
||||
{
|
||||
void Emit(AliasEventInfo eventInfo, IEmitter emitter);
|
||||
void Emit(ScalarEventInfo eventInfo, IEmitter emitter);
|
||||
void Emit(MappingStartEventInfo eventInfo, IEmitter emitter);
|
||||
void Emit(MappingEndEventInfo eventInfo, IEmitter emitter);
|
||||
void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter);
|
||||
void Emit(SequenceEndEventInfo eventInfo, IEmitter emitter);
|
||||
}
|
||||
}
|
||||
11
Assets/YamlDotNet/Serialization/IEventEmitter.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/IEventEmitter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05f7588b91e030f438b48c4af7ecf613
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/YamlDotNet/Serialization/INamingConvention.cs
Normal file
32
Assets/YamlDotNet/Serialization/INamingConvention.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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.
|
||||
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Translates property names according to a specific convention.
|
||||
/// </summary>
|
||||
public interface INamingConvention
|
||||
{
|
||||
string Apply(string value);
|
||||
}
|
||||
}
|
||||
11
Assets/YamlDotNet/Serialization/INamingConvention.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/INamingConvention.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9e2e0524133523428f9f2498f7c06f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/YamlDotNet/Serialization/INodeDeserializer.cs
Normal file
31
Assets/YamlDotNet/Serialization/INodeDeserializer.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
{
|
||||
public interface INodeDeserializer
|
||||
{
|
||||
bool Deserialize(IParser reader, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, out object? value);
|
||||
}
|
||||
}
|
||||
12
Assets/YamlDotNet/Serialization/INodeDeserializer.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/INodeDeserializer.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f27d06ef3f08024d8a6ee848351527a
|
||||
timeCreated: 1427145263
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/YamlDotNet/Serialization/INodeTypeResolver.cs
Normal file
40
Assets/YamlDotNet/Serialization/INodeTypeResolver.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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.Events;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
public interface INodeTypeResolver
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines the type of the specified node.
|
||||
/// </summary>
|
||||
/// <param name="nodeEvent">The node to be deserialized.</param>
|
||||
/// <param name="currentType">The type that has been determined so far.</param>
|
||||
/// <returns>
|
||||
/// true if <paramref name="currentType"/> has been resolved completely;
|
||||
/// false if the next type <see cref="INodeTypeResolver"/> should be invoked.
|
||||
/// </returns>
|
||||
bool Resolve(NodeEvent? nodeEvent, ref Type currentType);
|
||||
}
|
||||
}
|
||||
12
Assets/YamlDotNet/Serialization/INodeTypeResolver.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/INodeTypeResolver.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc7c4eab6abbae74eb74eee44a52e6a7
|
||||
timeCreated: 1427145267
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
67
Assets/YamlDotNet/Serialization/IObjectDescriptor.cs
Normal file
67
Assets/YamlDotNet/Serialization/IObjectDescriptor.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an object along with its type.
|
||||
/// </summary>
|
||||
public interface IObjectDescriptor
|
||||
{
|
||||
/// <summary>
|
||||
/// A reference to the object.
|
||||
/// </summary>
|
||||
object? Value { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The type that should be used when to interpret the <see cref="Value" />.
|
||||
/// </summary>
|
||||
Type Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of <see cref="Value" /> as determined by its container (e.g. a property).
|
||||
/// </summary>
|
||||
Type StaticType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The style to be used for scalars.
|
||||
/// </summary>
|
||||
ScalarStyle ScalarStyle { get; }
|
||||
}
|
||||
|
||||
public static class ObjectDescriptorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the Value property of the <paramref name="objectDescriptor"/> if it is not null.
|
||||
/// This is useful in all places that the value must not be null.
|
||||
/// </summary>
|
||||
/// <param name="objectDescriptor">An object descriptor.</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown when the Value is null</exception>
|
||||
/// <returns></returns>
|
||||
public static object NonNullValue(this IObjectDescriptor objectDescriptor)
|
||||
{
|
||||
return objectDescriptor.Value ?? throw new InvalidOperationException($"Attempted to use a IObjectDescriptor of type '{objectDescriptor.Type.FullName}' whose Value is null at a point whete it is invalid to do so. This may indicate a bug in YamlDotNet.");
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/YamlDotNet/Serialization/IObjectDescriptor.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/IObjectDescriptor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcb0a1a8415e8714ab58565d3f392aec
|
||||
timeCreated: 1427145266
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/YamlDotNet/Serialization/IObjectFactory.cs
Normal file
39
Assets/YamlDotNet/Serialization/IObjectFactory.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates instances of types.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This interface allows to provide a custom logic for creating instances during deserialization.
|
||||
/// </remarks>
|
||||
public interface IObjectFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an instance of the specified type.
|
||||
/// </summary>
|
||||
object Create(Type type);
|
||||
}
|
||||
}
|
||||
11
Assets/YamlDotNet/Serialization/IObjectFactory.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/IObjectFactory.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86a19edb69863084e9364dec9fcda8c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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.
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a strategy that walks through an object graph.
|
||||
/// </summary>
|
||||
public interface IObjectGraphTraversalStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Traverses the specified object graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph.</param>
|
||||
/// <param name="visitor">An <see cref="IObjectGraphVisitor{TContext}"/> that is to be notified during the traversal.</param>
|
||||
/// <param name="context">A <typeparamref name="TContext" /> that will be passed to the <paramref name="visitor" />.</param>
|
||||
void Traverse<TContext>(IObjectDescriptor graph, IObjectGraphVisitor<TContext> visitor, TContext context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33215c487a2a3f04cbbe41c318253ee0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
99
Assets/YamlDotNet/Serialization/IObjectGraphVisitor.cs
Normal file
99
Assets/YamlDotNet/Serialization/IObjectGraphVisitor.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
// 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;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Defined the interface of a type that can be notified during an object graph traversal.
|
||||
/// </summary>
|
||||
public interface IObjectGraphVisitor<TContext>
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates whether the specified value should be entered. This allows the visitor to
|
||||
/// override the handling of a particular object or type.
|
||||
/// </summary>
|
||||
/// <param name="value">The value that is about to be entered.</param>
|
||||
/// <param name="context">The context that this implementation depend on.</param>
|
||||
/// <returns>If the value is to be entered, returns true; otherwise returns false;</returns>
|
||||
bool Enter(IObjectDescriptor value, TContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the specified mapping should be entered. This allows the visitor to
|
||||
/// override the handling of a particular pair.
|
||||
/// </summary>
|
||||
/// <param name="key">The key of the mapping that is about to be entered.</param>
|
||||
/// <param name="value">The value of the mapping that is about to be entered.</param>
|
||||
/// <param name="context">The context that this implementation depend on.</param>
|
||||
/// <returns>If the mapping is to be entered, returns true; otherwise returns false;</returns>
|
||||
bool EnterMapping(IObjectDescriptor key, IObjectDescriptor value, TContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the specified mapping should be entered. This allows the visitor to
|
||||
/// override the handling of a particular pair. This overload should be invoked when the
|
||||
/// mapping is produced by an object's property.
|
||||
/// </summary>
|
||||
/// <param name="key">The <see cref="IPropertyDescriptor"/> that provided access to <paramref name="value"/>.</param>
|
||||
/// <param name="value">The value of the mapping that is about to be entered.</param>
|
||||
/// <param name="context">The context that this implementation depend on.</param>
|
||||
/// <returns>If the mapping is to be entered, returns true; otherwise returns false;</returns>
|
||||
bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, TContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the visitor that a scalar value has been encountered.
|
||||
/// </summary>
|
||||
/// <param name="scalar">The value of the scalar.</param>
|
||||
/// <param name="context">The context that this implementation depend on.</param>
|
||||
void VisitScalar(IObjectDescriptor scalar, TContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the visitor that the traversal of a mapping is about to begin.
|
||||
/// </summary>
|
||||
/// <param name="mapping">The value that corresponds to the mapping.</param>
|
||||
/// <param name="keyType">The static type of the keys of the mapping.</param>
|
||||
/// <param name="valueType">The static type of the values of the mapping.</param>
|
||||
/// <param name="context">The context that this implementation depend on.</param>
|
||||
void VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType, TContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the visitor that the traversal of a mapping has ended.
|
||||
/// </summary>
|
||||
/// <param name="mapping">The value that corresponds to the mapping.</param>
|
||||
/// <param name="context">The context that this implementation depend on.</param>
|
||||
void VisitMappingEnd(IObjectDescriptor mapping, TContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the visitor that the traversal of a sequence is about to begin.
|
||||
/// </summary>
|
||||
/// <param name="sequence">The value that corresponds to the sequence.</param>
|
||||
/// <param name="elementType">The static type of the elements of the sequence.</param>
|
||||
/// <param name="context">The context that this implementation depend on.</param>
|
||||
void VisitSequenceStart(IObjectDescriptor sequence, Type elementType, TContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the visitor that the traversal of a sequence has ended.
|
||||
/// </summary>
|
||||
/// <param name="sequence">The value that corresponds to the sequence.</param>
|
||||
/// <param name="context">The context that this implementation depend on.</param>
|
||||
void VisitSequenceEnd(IObjectDescriptor sequence, TContext context);
|
||||
}
|
||||
}
|
||||
11
Assets/YamlDotNet/Serialization/IObjectGraphVisitor.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/IObjectGraphVisitor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6232168616fce2428643fe75d1ed035
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/YamlDotNet/Serialization/IPropertyDescriptor.cs
Normal file
41
Assets/YamlDotNet/Serialization/IPropertyDescriptor.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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
|
||||
{
|
||||
public interface IPropertyDescriptor
|
||||
{
|
||||
string Name { get; }
|
||||
bool CanWrite { get; }
|
||||
Type Type { get; }
|
||||
Type? TypeOverride { get; set; }
|
||||
int Order { get; set; }
|
||||
ScalarStyle ScalarStyle { get; set; }
|
||||
|
||||
T GetCustomAttribute<T>() where T : Attribute;
|
||||
|
||||
IObjectDescriptor Read(object target);
|
||||
void Write(object target, object? value);
|
||||
}
|
||||
}
|
||||
12
Assets/YamlDotNet/Serialization/IPropertyDescriptor.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/IPropertyDescriptor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5985b699bccf7548a76738be6b6e551
|
||||
timeCreated: 1427145266
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user