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:
|
@@ -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.
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
public interface IRegistrationLocationSelectionSyntax<TBaseRegistrationType>
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the component in place of the already registered component of type <typeparamref name="TRegistrationType" />.
|
||||
/// </summary>
|
||||
void InsteadOf<TRegistrationType>() where TRegistrationType : TBaseRegistrationType;
|
||||
|
||||
/// <summary>
|
||||
/// Registers the component before the already registered component of type <typeparamref name="TRegistrationType" />.
|
||||
/// </summary>
|
||||
void Before<TRegistrationType>() where TRegistrationType : TBaseRegistrationType;
|
||||
|
||||
/// <summary>
|
||||
/// Registers the component after the already registered component of type <typeparamref name="TRegistrationType" />.
|
||||
/// </summary>
|
||||
void After<TRegistrationType>() where TRegistrationType : TBaseRegistrationType;
|
||||
|
||||
/// <summary>
|
||||
/// Registers the component before every other previously registered component.
|
||||
/// </summary>
|
||||
void OnTop();
|
||||
|
||||
/// <summary>
|
||||
/// Registers the component after every other previously registered component.
|
||||
/// </summary>
|
||||
void OnBottom();
|
||||
}
|
||||
|
||||
public interface ITrackingRegistrationLocationSelectionSyntax<TBaseRegistrationType>
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the component in place of the already registered component of type <typeparamref name="TRegistrationType" />.
|
||||
/// </summary>
|
||||
void InsteadOf<TRegistrationType>() where TRegistrationType : TBaseRegistrationType;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2e3d426fbc212f48b7a3b269a5ed7f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
66
Assets/YamlDotNet/Serialization/ISerializer.cs
Normal file
66
Assets/YamlDotNet/Serialization/ISerializer.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
// 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 ISerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Serializes the specified object.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> where to serialize the object.</param>
|
||||
/// <param name="graph">The object to serialize.</param>
|
||||
void Serialize(TextWriter writer, object graph);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified object into a string.
|
||||
/// </summary>
|
||||
/// <param name="graph">The object to serialize.</param>
|
||||
string Serialize(object graph);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified object.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter" /> where to serialize the object.</param>
|
||||
/// <param name="graph">The object to serialize.</param>
|
||||
/// <param name="type">The static type of the object to serialize.</param>
|
||||
void Serialize(TextWriter writer, object graph, Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified object.
|
||||
/// </summary>
|
||||
/// <param name="emitter">The <see cref="IEmitter" /> where to serialize the object.</param>
|
||||
/// <param name="graph">The object to serialize.</param>
|
||||
void Serialize(IEmitter emitter, object graph);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified object.
|
||||
/// </summary>
|
||||
/// <param name="emitter">The <see cref="IEmitter" /> where to serialize the object.</param>
|
||||
/// <param name="graph">The object to serialize.</param>
|
||||
/// <param name="type">The static type of the object to serialize.</param>
|
||||
void Serialize(IEmitter emitter, object graph, Type type);
|
||||
}
|
||||
}
|
11
Assets/YamlDotNet/Serialization/ISerializer.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/ISerializer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ae1bfa2f95d7684d9c16346c9c7a4de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Assets/YamlDotNet/Serialization/ITypeInspector.cs
Normal file
54
Assets/YamlDotNet/Serialization/ITypeInspector.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
// 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.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the properties of a type.
|
||||
/// </summary>
|
||||
public interface ITypeInspector
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all properties of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type whose properties are to be enumerated.</param>
|
||||
/// <param name="container">The actual object of type <paramref name="type"/> whose properties are to be enumerated. Can be null.</param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<IPropertyDescriptor> GetProperties(Type type, object? container);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property of the type with the specified name.
|
||||
/// </summary>
|
||||
/// <param name="type">The type whose properties are to be searched.</param>
|
||||
/// <param name="container">The actual object of type <paramref name="type"/> whose properties are to be searched. Can be null.</param>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
/// <param name="ignoreUnmatched">
|
||||
/// Determines if an exception or null should be returned if <paramref name="name"/> can't be
|
||||
/// found in <paramref name="type"/>
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
IPropertyDescriptor GetProperty(Type type, object? container, string name, [MaybeNullWhen(true)] bool ignoreUnmatched);
|
||||
}
|
||||
}
|
12
Assets/YamlDotNet/Serialization/ITypeInspector.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/ITypeInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 915f534464f498641ab97a0e2c651b77
|
||||
timeCreated: 1427145265
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/YamlDotNet/Serialization/ITypeResolver.cs
Normal file
33
Assets/YamlDotNet/Serialization/ITypeResolver.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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>
|
||||
/// Resolves the type of values.
|
||||
/// </summary>
|
||||
public interface ITypeResolver
|
||||
{
|
||||
Type Resolve(Type staticType, object? actualValue);
|
||||
}
|
||||
}
|
12
Assets/YamlDotNet/Serialization/ITypeResolver.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/ITypeResolver.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c3bd4a3f0eca6e4f92ba855bc058d25
|
||||
timeCreated: 1427145264
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
32
Assets/YamlDotNet/Serialization/IValueDeserializer.cs
Normal file
32
Assets/YamlDotNet/Serialization/IValueDeserializer.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.
|
||||
|
||||
using System;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
public interface IValueDeserializer
|
||||
{
|
||||
object? DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer);
|
||||
}
|
||||
}
|
12
Assets/YamlDotNet/Serialization/IValueDeserializer.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/IValueDeserializer.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1356281a3d017849a3240d70d9cfacd
|
||||
timeCreated: 1427145266
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
30
Assets/YamlDotNet/Serialization/IValuePromise.cs
Normal file
30
Assets/YamlDotNet/Serialization/IValuePromise.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 System;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
public interface IValuePromise
|
||||
{
|
||||
event Action<object?> ValueAvailable;
|
||||
}
|
||||
}
|
12
Assets/YamlDotNet/Serialization/IValuePromise.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/IValuePromise.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 432dc17fcd3e2cb40990aab6122f075f
|
||||
timeCreated: 1427145264
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
31
Assets/YamlDotNet/Serialization/IValueSerializer.cs
Normal file
31
Assets/YamlDotNet/Serialization/IValueSerializer.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 IValueSerializer
|
||||
{
|
||||
void SerializeValue(IEmitter emitter, object? value, Type? type);
|
||||
}
|
||||
}
|
11
Assets/YamlDotNet/Serialization/IValueSerializer.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/IValueSerializer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e24a662d1be166743945e1986cb19cb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
67
Assets/YamlDotNet/Serialization/IYamlConvertible.cs
Normal file
67
Assets/YamlDotNet/Serialization/IYamlConvertible.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>
|
||||
/// Allows an object to customize how it is serialized and deserialized.
|
||||
/// </summary>
|
||||
public interface IYamlConvertible
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads this object's state from a YAML parser.
|
||||
/// </summary>
|
||||
/// <param name="parser">The parser where the object's state should be read from.</param>
|
||||
/// <param name="expectedType">The type that the deserializer is expecting.</param>
|
||||
/// <param name="nestedObjectDeserializer">
|
||||
/// A function that will use the current deserializer
|
||||
/// to read an object of the given type from the parser.
|
||||
/// </param>
|
||||
void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer);
|
||||
|
||||
/// <summary>
|
||||
/// Writes this object's state to a YAML emitter.
|
||||
/// </summary>
|
||||
/// <param name="emitter">The emitter where the object's state should be written to.</param>
|
||||
/// <param name="nestedObjectSerializer">A function that will use the current serializer to write an object to the emitter.</param>
|
||||
void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a function that is used to deserialize an object of the given type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type that the deserializer should read.</param>
|
||||
/// <returns>Returns the object that was deserialized.</returns>
|
||||
public delegate object? ObjectDeserializer(Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Represents a function that is used to serialize an object of the given type.
|
||||
/// </summary>
|
||||
/// <param name="value">The object to be serialized.</param>
|
||||
/// <param name="type">
|
||||
/// The type that should be considered when emitting the object.
|
||||
/// If null, the actual type of the <paramref name="value" /> is used.
|
||||
/// </param>
|
||||
public delegate void ObjectSerializer(object? value, Type? type = null);
|
||||
}
|
11
Assets/YamlDotNet/Serialization/IYamlConvertible.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/IYamlConvertible.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0611a055d6fbe6e49bce224457ee9065
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Assets/YamlDotNet/Serialization/IYamlSerializable.cs
Normal file
43
Assets/YamlDotNet/Serialization/IYamlSerializable.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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>
|
||||
/// Allows an object to customize how it is serialized and deserialized.
|
||||
/// </summary>
|
||||
[Obsolete("Please use IYamlConvertible instead")]
|
||||
public interface IYamlSerializable
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads this object's state from a YAML parser.
|
||||
/// </summary>
|
||||
void ReadYaml(IParser parser);
|
||||
|
||||
/// <summary>
|
||||
/// Writes this object's state to a YAML emitter.
|
||||
/// </summary>
|
||||
void WriteYaml(IEmitter emitter);
|
||||
}
|
||||
}
|
11
Assets/YamlDotNet/Serialization/IYamlSerializable.cs.meta
Normal file
11
Assets/YamlDotNet/Serialization/IYamlSerializable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f42bad1c9f9fdf242b696f20c2e66259
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
47
Assets/YamlDotNet/Serialization/IYamlTypeConverter.cs
Normal file
47
Assets/YamlDotNet/Serialization/IYamlTypeConverter.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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>
|
||||
/// Allows to customize how a type is serialized and deserialized.
|
||||
/// </summary>
|
||||
public interface IYamlTypeConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the current converter supports converting the specified type.
|
||||
/// </summary>
|
||||
bool Accepts(Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Reads an object's state from a YAML parser.
|
||||
/// </summary>
|
||||
object? ReadYaml(IParser parser, Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified object's state to a YAML emitter.
|
||||
/// </summary>
|
||||
void WriteYaml(IEmitter emitter, object? value, Type type);
|
||||
}
|
||||
}
|
12
Assets/YamlDotNet/Serialization/IYamlTypeConverter.cs.meta
Normal file
12
Assets/YamlDotNet/Serialization/IYamlTypeConverter.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f114886060e4acf46b36ac2c9f610cc3
|
||||
timeCreated: 1427145267
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
237
Assets/YamlDotNet/Serialization/LazyComponentRegistrationList.cs
Normal file
237
Assets/YamlDotNet/Serialization/LazyComponentRegistrationList.cs
Normal file
@@ -0,0 +1,237 @@
|
||||
// This file is part of YamlDotNet - A .NET library for YAML.
|
||||
// Copyright (c) Antoine Aubry and contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
internal sealed class LazyComponentRegistrationList<TArgument, TComponent> : IEnumerable<Func<TArgument, TComponent>>
|
||||
{
|
||||
private readonly List<LazyComponentRegistration> entries = new List<LazyComponentRegistration>();
|
||||
|
||||
public LazyComponentRegistrationList<TArgument, TComponent> Clone()
|
||||
{
|
||||
var clone = new LazyComponentRegistrationList<TArgument, TComponent>();
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
clone.entries.Add(entry);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
public sealed class LazyComponentRegistration
|
||||
{
|
||||
public readonly Type ComponentType;
|
||||
public readonly Func<TArgument, TComponent> Factory;
|
||||
|
||||
public LazyComponentRegistration(Type componentType, Func<TArgument, TComponent> factory)
|
||||
{
|
||||
ComponentType = componentType;
|
||||
Factory = factory;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TrackingLazyComponentRegistration
|
||||
{
|
||||
public readonly Type ComponentType;
|
||||
public readonly Func<TComponent, TArgument, TComponent> Factory;
|
||||
|
||||
public TrackingLazyComponentRegistration(Type componentType, Func<TComponent, TArgument, TComponent> factory)
|
||||
{
|
||||
ComponentType = componentType;
|
||||
Factory = factory;
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(Type componentType, Func<TArgument, TComponent> factory)
|
||||
{
|
||||
entries.Add(new LazyComponentRegistration(componentType, factory));
|
||||
}
|
||||
|
||||
public void Remove(Type componentType)
|
||||
{
|
||||
for (var i = 0; i < entries.Count; ++i)
|
||||
{
|
||||
if (entries[i].ComponentType == componentType)
|
||||
{
|
||||
entries.RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new KeyNotFoundException($"A component registration of type '{componentType.FullName}' was not found.");
|
||||
}
|
||||
|
||||
public int Count => entries.Count;
|
||||
|
||||
public IEnumerable<Func<TArgument, TComponent>> InReverseOrder
|
||||
{
|
||||
get
|
||||
{
|
||||
for (var i = entries.Count - 1; i >= 0; --i)
|
||||
{
|
||||
yield return entries[i].Factory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IRegistrationLocationSelectionSyntax<TComponent> CreateRegistrationLocationSelector(
|
||||
Type componentType,
|
||||
Func<TArgument, TComponent> factory
|
||||
)
|
||||
{
|
||||
return new RegistrationLocationSelector(
|
||||
this,
|
||||
new LazyComponentRegistration(componentType, factory)
|
||||
);
|
||||
}
|
||||
|
||||
public ITrackingRegistrationLocationSelectionSyntax<TComponent> CreateTrackingRegistrationLocationSelector(
|
||||
Type componentType,
|
||||
Func<TComponent, TArgument, TComponent> factory
|
||||
)
|
||||
{
|
||||
return new TrackingRegistrationLocationSelector(
|
||||
this,
|
||||
new TrackingLazyComponentRegistration(componentType, factory)
|
||||
);
|
||||
}
|
||||
|
||||
public IEnumerator<Func<TArgument, TComponent>> GetEnumerator()
|
||||
{
|
||||
return entries.Select(e => e.Factory).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
private int IndexOfRegistration(Type registrationType)
|
||||
{
|
||||
for (var i = 0; i < entries.Count; ++i)
|
||||
{
|
||||
if (registrationType == entries[i].ComponentType)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void EnsureNoDuplicateRegistrationType(Type componentType)
|
||||
{
|
||||
if (IndexOfRegistration(componentType) != -1)
|
||||
{
|
||||
throw new InvalidOperationException($"A component of type '{componentType.FullName}' has already been registered.");
|
||||
}
|
||||
}
|
||||
|
||||
private int EnsureRegistrationExists<TRegistrationType>()
|
||||
{
|
||||
var registrationIndex = IndexOfRegistration(typeof(TRegistrationType));
|
||||
if (registrationIndex == -1)
|
||||
{
|
||||
throw new InvalidOperationException($"A component of type '{typeof(TRegistrationType).FullName}' has not been registered.");
|
||||
}
|
||||
return registrationIndex;
|
||||
}
|
||||
|
||||
private class RegistrationLocationSelector : IRegistrationLocationSelectionSyntax<TComponent>
|
||||
{
|
||||
private readonly LazyComponentRegistrationList<TArgument, TComponent> registrations;
|
||||
private readonly LazyComponentRegistration newRegistration;
|
||||
|
||||
public RegistrationLocationSelector(LazyComponentRegistrationList<TArgument, TComponent> registrations, LazyComponentRegistration newRegistration)
|
||||
{
|
||||
this.registrations = registrations;
|
||||
this.newRegistration = newRegistration;
|
||||
}
|
||||
|
||||
void IRegistrationLocationSelectionSyntax<TComponent>.InsteadOf<TRegistrationType>()
|
||||
{
|
||||
if (newRegistration.ComponentType != typeof(TRegistrationType))
|
||||
{
|
||||
registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
|
||||
}
|
||||
|
||||
var registrationIndex = registrations.EnsureRegistrationExists<TRegistrationType>();
|
||||
registrations.entries[registrationIndex] = newRegistration;
|
||||
}
|
||||
|
||||
void IRegistrationLocationSelectionSyntax<TComponent>.After<TRegistrationType>()
|
||||
{
|
||||
registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
|
||||
var registrationIndex = registrations.EnsureRegistrationExists<TRegistrationType>();
|
||||
registrations.entries.Insert(registrationIndex + 1, newRegistration);
|
||||
}
|
||||
|
||||
void IRegistrationLocationSelectionSyntax<TComponent>.Before<TRegistrationType>()
|
||||
{
|
||||
registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
|
||||
var registrationIndex = registrations.EnsureRegistrationExists<TRegistrationType>();
|
||||
registrations.entries.Insert(registrationIndex, newRegistration);
|
||||
}
|
||||
|
||||
void IRegistrationLocationSelectionSyntax<TComponent>.OnBottom()
|
||||
{
|
||||
registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
|
||||
registrations.entries.Add(newRegistration);
|
||||
}
|
||||
|
||||
void IRegistrationLocationSelectionSyntax<TComponent>.OnTop()
|
||||
{
|
||||
registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
|
||||
registrations.entries.Insert(0, newRegistration);
|
||||
}
|
||||
}
|
||||
|
||||
private class TrackingRegistrationLocationSelector : ITrackingRegistrationLocationSelectionSyntax<TComponent>
|
||||
{
|
||||
private readonly LazyComponentRegistrationList<TArgument, TComponent> registrations;
|
||||
private readonly TrackingLazyComponentRegistration newRegistration;
|
||||
|
||||
public TrackingRegistrationLocationSelector(LazyComponentRegistrationList<TArgument, TComponent> registrations, TrackingLazyComponentRegistration newRegistration)
|
||||
{
|
||||
this.registrations = registrations;
|
||||
this.newRegistration = newRegistration;
|
||||
}
|
||||
|
||||
void ITrackingRegistrationLocationSelectionSyntax<TComponent>.InsteadOf<TRegistrationType>()
|
||||
{
|
||||
if (newRegistration.ComponentType != typeof(TRegistrationType))
|
||||
{
|
||||
registrations.EnsureNoDuplicateRegistrationType(newRegistration.ComponentType);
|
||||
}
|
||||
|
||||
var registrationIndex = registrations.EnsureRegistrationExists<TRegistrationType>();
|
||||
var innerComponentFactory = registrations.entries[registrationIndex].Factory;
|
||||
registrations.entries[registrationIndex] = new LazyComponentRegistration(
|
||||
newRegistration.ComponentType,
|
||||
arg => newRegistration.Factory(innerComponentFactory(arg), arg)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 677d4a413af78344592ad924106c4a5a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,64 @@
|
||||
// This file is part of YamlDotNet - A .NET library for YAML.
|
||||
// Copyright (c) Antoine Aubry and contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace YamlDotNet.Serialization
|
||||
{
|
||||
internal static class LazyComponentRegistrationListExtensions
|
||||
{
|
||||
public static TComponent BuildComponentChain<TComponent>(this LazyComponentRegistrationList<TComponent, TComponent> registrations, TComponent innerComponent)
|
||||
{
|
||||
var outerComponent = registrations.InReverseOrder.Aggregate(
|
||||
innerComponent,
|
||||
(inner, factory) => factory(inner)
|
||||
);
|
||||
|
||||
return outerComponent;
|
||||
}
|
||||
|
||||
public static TComponent BuildComponentChain<TArgument, TComponent>(this LazyComponentRegistrationList<TArgument, TComponent> registrations, TComponent innerComponent, Func<TComponent, TArgument> argumentBuilder)
|
||||
{
|
||||
var outerComponent = registrations.InReverseOrder.Aggregate(
|
||||
innerComponent,
|
||||
(inner, factory) => factory(argumentBuilder(inner))
|
||||
);
|
||||
|
||||
return outerComponent;
|
||||
}
|
||||
|
||||
public static List<TComponent> BuildComponentList<TComponent>(this LazyComponentRegistrationList<Nothing, TComponent> registrations)
|
||||
{
|
||||
return registrations
|
||||
.Select(factory => factory(default))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static List<TComponent> BuildComponentList<TArgument, TComponent>(this LazyComponentRegistrationList<TArgument, TComponent> registrations, TArgument argument)
|
||||
{
|
||||
return registrations
|
||||
.Select(factory => factory(argument))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89ef072424fd19149af14e3a2aa858aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
Assets/YamlDotNet/Serialization/NamingConventions.meta
Normal file
9
Assets/YamlDotNet/Serialization/NamingConventions.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 767c978518279084085a6e65bcb24a43
|
||||
folderAsset: yes
|
||||
timeCreated: 1427145262
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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 YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NamingConventions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert the string with underscores (this_is_a_test) or hyphens (this-is-a-test) to
|
||||
/// camel case (thisIsATest). Camel case is the same as Pascal case, except the first letter
|
||||
/// is lowercase.
|
||||
/// </summary>
|
||||
public sealed class CamelCaseNamingConvention : INamingConvention
|
||||
{
|
||||
[Obsolete("Use the Instance static field instead of creating new instances")]
|
||||
public CamelCaseNamingConvention() { }
|
||||
|
||||
public string Apply(string value)
|
||||
{
|
||||
return value.ToCamelCase();
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
public static readonly INamingConvention Instance = new CamelCaseNamingConvention();
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32043fa3c3d7af6489b8238353dcf810
|
||||
timeCreated: 1427145263
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,44 @@
|
||||
// This file is part of YamlDotNet - A .NET library for YAML.
|
||||
// Copyright (c) Antoine Aubry and contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NamingConventions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert the string from camelcase (thisIsATest) to a hyphenated (this-is-a-test) string
|
||||
/// </summary>
|
||||
public sealed class HyphenatedNamingConvention : INamingConvention
|
||||
{
|
||||
[Obsolete("Use the Instance static field instead of creating new instances")]
|
||||
public HyphenatedNamingConvention() { }
|
||||
|
||||
public string Apply(string value)
|
||||
{
|
||||
return value.FromCamelCase("-");
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
public static readonly INamingConvention Instance = new HyphenatedNamingConvention();
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d393465f17a55814a8ecb04e77f1e25c
|
||||
timeCreated: 1427145266
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,42 @@
|
||||
// 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.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NamingConventions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert the string with underscores (this_is_a_test) or hyphens (this-is-a-test) to
|
||||
/// pascal case (ThisIsATest). Pascal case is the same as camel case, except the first letter
|
||||
/// is uppercase.
|
||||
/// </summary>
|
||||
public sealed class LowerCaseNamingConvention : INamingConvention
|
||||
{
|
||||
private LowerCaseNamingConvention() { }
|
||||
|
||||
public string Apply(string value)
|
||||
{
|
||||
return value.ToCamelCase().ToLower();
|
||||
}
|
||||
|
||||
public static readonly INamingConvention Instance = new LowerCaseNamingConvention();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5d44f37af8ab5940a9f28a2b2b80184
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,44 @@
|
||||
// This file is part of YamlDotNet - A .NET library for YAML.
|
||||
// Copyright (c) Antoine Aubry and contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
namespace YamlDotNet.Serialization.NamingConventions
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs no naming conversion.
|
||||
/// </summary>
|
||||
public sealed class NullNamingConvention : INamingConvention
|
||||
{
|
||||
[Obsolete("Use the Instance static field instead of creating new instances")]
|
||||
public NullNamingConvention() { }
|
||||
|
||||
public string Apply(string value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
public static readonly INamingConvention Instance = new NullNamingConvention();
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f1957c241ea377499c1656388ff9122
|
||||
timeCreated: 1427145263
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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 YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NamingConventions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert the string with underscores (this_is_a_test) or hyphens (this-is-a-test) to
|
||||
/// pascal case (ThisIsATest). Pascal case is the same as camel case, except the first letter
|
||||
/// is uppercase.
|
||||
/// </summary>
|
||||
public sealed class PascalCaseNamingConvention : INamingConvention
|
||||
{
|
||||
[Obsolete("Use the Instance static field instead of creating new instances")]
|
||||
public PascalCaseNamingConvention() { }
|
||||
|
||||
public string Apply(string value)
|
||||
{
|
||||
return value.ToPascalCase();
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
public static readonly INamingConvention Instance = new PascalCaseNamingConvention();
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0514b2a4f30517e42bc79c445fe75383
|
||||
timeCreated: 1427145262
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,44 @@
|
||||
// This file is part of YamlDotNet - A .NET library for YAML.
|
||||
// Copyright (c) Antoine Aubry and contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NamingConventions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert the string from camelcase (thisIsATest) to a underscored (this_is_a_test) string
|
||||
/// </summary>
|
||||
public sealed class UnderscoredNamingConvention : INamingConvention
|
||||
{
|
||||
[Obsolete("Use the Instance static field instead of creating new instances")]
|
||||
public UnderscoredNamingConvention() { }
|
||||
|
||||
public string Apply(string value)
|
||||
{
|
||||
return value.FromCamelCase("_");
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
public static readonly INamingConvention Instance = new UnderscoredNamingConvention();
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc07ca72c2bad00498d0cd0594f69151
|
||||
timeCreated: 1427145266
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
Assets/YamlDotNet/Serialization/NodeDeserializers.meta
Normal file
9
Assets/YamlDotNet/Serialization/NodeDeserializers.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a4c2b9d6803c4b44ad65cedc400e3d1
|
||||
folderAsset: yes
|
||||
timeCreated: 1427145262
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,119 @@
|
||||
// This file is part of YamlDotNet - A .NET library for YAML.
|
||||
// Copyright (c) Antoine Aubry and contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using YamlDotNet.Core;
|
||||
|
||||
namespace YamlDotNet.Serialization.NodeDeserializers
|
||||
{
|
||||
public sealed class ArrayNodeDeserializer : INodeDeserializer
|
||||
{
|
||||
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, out object? value)
|
||||
{
|
||||
if (!expectedType.IsArray)
|
||||
{
|
||||
value = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
var itemType = expectedType.GetElementType()!; // Arrays always have an element type
|
||||
|
||||
var items = new ArrayList();
|
||||
CollectionNodeDeserializer.DeserializeHelper(itemType, parser, nestedObjectDeserializer, items, true);
|
||||
|
||||
var array = Array.CreateInstance(itemType, items.Count);
|
||||
items.CopyTo(array, 0);
|
||||
|
||||
value = array;
|
||||
return true;
|
||||
}
|
||||
|
||||
private sealed class ArrayList : IList
|
||||
{
|
||||
private object?[] data;
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field is uninitialized. Initialized inside Clear()
|
||||
public ArrayList()
|
||||
#pragma warning restore CS8618 // Non-nullable field is uninitialized.
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
public int Add(object? value)
|
||||
{
|
||||
if (Count == data.Length)
|
||||
{
|
||||
Array.Resize(ref data, data.Length * 2);
|
||||
}
|
||||
data[Count] = value;
|
||||
return Count++;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
data = new object[10];
|
||||
Count = 0;
|
||||
}
|
||||
|
||||
bool IList.Contains(object? value) => throw new NotSupportedException();
|
||||
int IList.IndexOf(object? value) => throw new NotSupportedException();
|
||||
void IList.Insert(int index, object? value) => throw new NotSupportedException();
|
||||
void IList.Remove(object? value) => throw new NotSupportedException();
|
||||
void IList.RemoveAt(int index) => throw new NotSupportedException();
|
||||
|
||||
public bool IsFixedSize => false;
|
||||
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public object? this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return data[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
data[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyTo(Array array, int index)
|
||||
{
|
||||
Array.Copy(data, 0, array, index, Count);
|
||||
}
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public bool IsSynchronized => false;
|
||||
public object SyncRoot => data;
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
for (var i = 0; i < Count; ++i)
|
||||
{
|
||||
yield return data[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20118ab09905856488b432270429ae5b
|
||||
timeCreated: 1427145263
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,111 @@
|
||||
// This file is part of YamlDotNet - A .NET library for YAML.
|
||||
// Copyright (c) Antoine Aubry and contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Helpers;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NodeDeserializers
|
||||
{
|
||||
public sealed class CollectionNodeDeserializer : INodeDeserializer
|
||||
{
|
||||
private readonly IObjectFactory objectFactory;
|
||||
|
||||
public CollectionNodeDeserializer(IObjectFactory objectFactory)
|
||||
{
|
||||
this.objectFactory = objectFactory ?? throw new ArgumentNullException(nameof(objectFactory));
|
||||
}
|
||||
|
||||
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, out object? value)
|
||||
{
|
||||
IList? list;
|
||||
var canUpdate = true;
|
||||
Type itemType;
|
||||
var genericCollectionType = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(ICollection<>));
|
||||
if (genericCollectionType != null)
|
||||
{
|
||||
var genericArguments = genericCollectionType.GetGenericArguments();
|
||||
itemType = genericArguments[0];
|
||||
|
||||
value = objectFactory.Create(expectedType);
|
||||
list = value as IList;
|
||||
if (list == null)
|
||||
{
|
||||
// Uncommon case where a type implements IList<T> but not IList
|
||||
var genericListType = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(IList<>));
|
||||
canUpdate = genericListType != null;
|
||||
list = (IList?)Activator.CreateInstance(typeof(GenericCollectionToNonGenericAdapter<>).MakeGenericType(itemType), value);
|
||||
}
|
||||
}
|
||||
else if (typeof(IList).IsAssignableFrom(expectedType))
|
||||
{
|
||||
itemType = typeof(object);
|
||||
|
||||
value = objectFactory.Create(expectedType);
|
||||
list = (IList)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
DeserializeHelper(itemType, parser, nestedObjectDeserializer, list!, canUpdate);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void DeserializeHelper(Type tItem, IParser parser, Func<IParser, Type, object?> nestedObjectDeserializer, IList result, bool canUpdate)
|
||||
{
|
||||
parser.Consume<SequenceStart>();
|
||||
while (!parser.TryConsume<SequenceEnd>(out var _))
|
||||
{
|
||||
var current = parser.Current;
|
||||
|
||||
var value = nestedObjectDeserializer(parser, tItem);
|
||||
if (value is IValuePromise promise)
|
||||
{
|
||||
if (canUpdate)
|
||||
{
|
||||
var index = result.Add(tItem.IsValueType() ? Activator.CreateInstance(tItem) : null);
|
||||
promise.ValueAvailable += v => result[index] = TypeConverter.ChangeType(v, tItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ForwardAnchorNotSupportedException(
|
||||
current?.Start ?? Mark.Empty,
|
||||
current?.End ?? Mark.Empty,
|
||||
"Forward alias references are not allowed because this type does not implement IList<>"
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(TypeConverter.ChangeType(value, tItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3d1d09d7ca82fa46841cf8b486dc14e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,144 @@
|
||||
// This file is part of YamlDotNet - A .NET library for YAML.
|
||||
// Copyright (c) Antoine Aubry and contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Helpers;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NodeDeserializers
|
||||
{
|
||||
public sealed class DictionaryNodeDeserializer : INodeDeserializer
|
||||
{
|
||||
private readonly IObjectFactory objectFactory;
|
||||
|
||||
public DictionaryNodeDeserializer(IObjectFactory objectFactory)
|
||||
{
|
||||
this.objectFactory = objectFactory ?? throw new ArgumentNullException(nameof(objectFactory));
|
||||
}
|
||||
|
||||
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, out object? value)
|
||||
{
|
||||
IDictionary? dictionary;
|
||||
Type keyType, valueType;
|
||||
var genericDictionaryType = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(IDictionary<,>));
|
||||
if (genericDictionaryType != null)
|
||||
{
|
||||
var genericArguments = genericDictionaryType.GetGenericArguments();
|
||||
keyType = genericArguments[0];
|
||||
valueType = genericArguments[1];
|
||||
|
||||
value = objectFactory.Create(expectedType);
|
||||
|
||||
dictionary = value as IDictionary;
|
||||
if (dictionary == null)
|
||||
{
|
||||
// Uncommon case where a type implements IDictionary<TKey, TValue> but not IDictionary
|
||||
dictionary = (IDictionary?)Activator.CreateInstance(typeof(GenericDictionaryToNonGenericAdapter<,>).MakeGenericType(keyType, valueType), value);
|
||||
}
|
||||
}
|
||||
else if (typeof(IDictionary).IsAssignableFrom(expectedType))
|
||||
{
|
||||
keyType = typeof(object);
|
||||
valueType = typeof(object);
|
||||
|
||||
value = objectFactory.Create(expectedType);
|
||||
dictionary = (IDictionary)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
DeserializeHelper(keyType, valueType, parser, nestedObjectDeserializer, dictionary!);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void DeserializeHelper(Type tKey, Type tValue, IParser parser, Func<IParser, Type, object?> nestedObjectDeserializer, IDictionary result)
|
||||
{
|
||||
parser.Consume<MappingStart>();
|
||||
while (!parser.TryConsume<MappingEnd>(out var _))
|
||||
{
|
||||
var key = nestedObjectDeserializer(parser, tKey);
|
||||
var value = nestedObjectDeserializer(parser, tValue);
|
||||
var valuePromise = value as IValuePromise;
|
||||
|
||||
if (key is IValuePromise keyPromise)
|
||||
{
|
||||
if (valuePromise == null)
|
||||
{
|
||||
// Key is pending, value is known
|
||||
keyPromise.ValueAvailable += v => result[v!] = value!;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Both key and value are pending. We need to wait until both of them become available.
|
||||
var hasFirstPart = false;
|
||||
|
||||
keyPromise.ValueAvailable += v =>
|
||||
{
|
||||
if (hasFirstPart)
|
||||
{
|
||||
result[v!] = value!;
|
||||
}
|
||||
else
|
||||
{
|
||||
key = v!;
|
||||
hasFirstPart = true;
|
||||
}
|
||||
};
|
||||
|
||||
valuePromise.ValueAvailable += v =>
|
||||
{
|
||||
if (hasFirstPart)
|
||||
{
|
||||
result[key] = v!;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = v;
|
||||
hasFirstPart = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (valuePromise == null)
|
||||
{
|
||||
// Happy path: both key and value are known
|
||||
result[key!] = value!;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Key is known, value is pending
|
||||
valuePromise.ValueAvailable += v => result[key!] = v!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fe68add59e580848b7d981ac8f2f0a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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 System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NodeDeserializers
|
||||
{
|
||||
public sealed class EnumerableNodeDeserializer : INodeDeserializer
|
||||
{
|
||||
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, out object? value)
|
||||
{
|
||||
Type itemsType;
|
||||
if (expectedType == typeof(IEnumerable))
|
||||
{
|
||||
itemsType = typeof(object);
|
||||
}
|
||||
else
|
||||
{
|
||||
var iEnumerable = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(IEnumerable<>));
|
||||
if (iEnumerable != expectedType)
|
||||
{
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
itemsType = iEnumerable.GetGenericArguments()[0];
|
||||
}
|
||||
|
||||
var collectionType = typeof(List<>).MakeGenericType(itemsType);
|
||||
value = nestedObjectDeserializer(parser, collectionType);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b63af2cc4a9f5d4cbbadbdac863e5df
|
||||
timeCreated: 1427145264
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,63 @@
|
||||
// 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.NodeDeserializers
|
||||
{
|
||||
public sealed class NullNodeDeserializer : INodeDeserializer
|
||||
{
|
||||
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, out object? value)
|
||||
{
|
||||
value = null;
|
||||
if (parser.Accept<NodeEvent>(out var evt))
|
||||
{
|
||||
if (NodeIsNull(evt))
|
||||
{
|
||||
parser.SkipThisAndNestedEvents();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool NodeIsNull(NodeEvent nodeEvent)
|
||||
{
|
||||
// http://yaml.org/type/null.html
|
||||
|
||||
if (nodeEvent.Tag == "tag:yaml.org,2002:null")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nodeEvent is Scalar scalar && scalar.Style == Core.ScalarStyle.Plain)
|
||||
{
|
||||
var value = scalar.Value;
|
||||
return value == "" || value == "~" || value == "null" || value == "Null" || value == "NULL";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dc4eb3386e00254a90e737f7663d298
|
||||
timeCreated: 1427145263
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,100 @@
|
||||
// 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.Runtime.Serialization;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization.Utilities;
|
||||
|
||||
namespace YamlDotNet.Serialization.NodeDeserializers
|
||||
{
|
||||
public sealed class ObjectNodeDeserializer : INodeDeserializer
|
||||
{
|
||||
private readonly IObjectFactory objectFactory;
|
||||
private readonly ITypeInspector typeDescriptor;
|
||||
private readonly bool ignoreUnmatched;
|
||||
|
||||
public ObjectNodeDeserializer(IObjectFactory objectFactory, ITypeInspector typeDescriptor, bool ignoreUnmatched)
|
||||
{
|
||||
this.objectFactory = objectFactory ?? throw new ArgumentNullException(nameof(objectFactory));
|
||||
this.typeDescriptor = typeDescriptor ?? throw new ArgumentNullException(nameof(typeDescriptor));
|
||||
this.ignoreUnmatched = ignoreUnmatched;
|
||||
}
|
||||
|
||||
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, out object? value)
|
||||
{
|
||||
if (!parser.TryConsume<MappingStart>(out var mapping))
|
||||
{
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Strip off the nullable type, if present. This is needed for nullable structs.
|
||||
var implementationType = Nullable.GetUnderlyingType(expectedType) ?? expectedType;
|
||||
|
||||
value = objectFactory.Create(implementationType);
|
||||
while (!parser.TryConsume<MappingEnd>(out var _))
|
||||
{
|
||||
var propertyName = parser.Consume<Scalar>();
|
||||
try
|
||||
{
|
||||
var property = typeDescriptor.GetProperty(implementationType, null, propertyName.Value, ignoreUnmatched);
|
||||
if (property == null)
|
||||
{
|
||||
parser.SkipThisAndNestedEvents();
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyValue = nestedObjectDeserializer(parser, property.Type);
|
||||
if (propertyValue is IValuePromise propertyValuePromise)
|
||||
{
|
||||
var valueRef = value;
|
||||
propertyValuePromise.ValueAvailable += v =>
|
||||
{
|
||||
var convertedValue = TypeConverter.ChangeType(v, property.Type);
|
||||
property.Write(valueRef, convertedValue);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
var convertedValue = TypeConverter.ChangeType(propertyValue, property.Type);
|
||||
property.Write(value, convertedValue);
|
||||
}
|
||||
}
|
||||
catch (SerializationException ex)
|
||||
{
|
||||
throw new YamlException(propertyName.Start, propertyName.End, ex.Message);
|
||||
}
|
||||
catch (YamlException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new YamlException(propertyName.Start, propertyName.End, "Exception during deserialization", ex);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 203cafd2ca433854ab6bb7dcc51b861a
|
||||
timeCreated: 1427145263
|
||||
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