-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to YamlDotNet version 12.3.1
- Loading branch information
Showing
13 changed files
with
125 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Microsoft.DocAsCode.YamlSerialization/Microsoft.DocAsCode.YamlSerialization.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<PackageReference Include="YamlDotNet" Version="6.0.0" /> | ||
<PackageReference Include="YamlDotNet" Version="12.3.1" /> | ||
</ItemGroup> | ||
</Project> |
37 changes: 37 additions & 0 deletions
37
src/Microsoft.DocAsCode.YamlSerialization/ObjectGraphVisitors/ExclusiveObjectGraphVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.YamlSerialization.ObjectGraphVisitors | ||
{ | ||
using System; | ||
using System.ComponentModel; | ||
using YamlDotNet.Core; | ||
using YamlDotNet.Serialization; | ||
using YamlDotNet.Serialization.ObjectGraphVisitors; | ||
|
||
/// <summary> | ||
/// YamlDotNet behavior has changed since 6.x so a custom version which doesn't check on EnterMapping. | ||
/// </summary> | ||
internal sealed class ExclusiveObjectGraphVisitor : ChainedObjectGraphVisitor | ||
{ | ||
public ExclusiveObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor) | ||
: base(nextVisitor) | ||
{ | ||
} | ||
|
||
private static object GetDefault(Type type) | ||
{ | ||
return type.IsValueType ? Activator.CreateInstance(type) : null; | ||
} | ||
|
||
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context) | ||
{ | ||
var defaultValueAttribute = key.GetCustomAttribute<DefaultValueAttribute>(); | ||
object defaultValue = defaultValueAttribute != null | ||
? defaultValueAttribute.Value | ||
: GetDefault(key.Type); | ||
|
||
return !Equals(value.Value, defaultValue) && base.EnterMapping(key, value, context); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Microsoft.DocAsCode.YamlSerialization/SerializationOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.DocAsCode.YamlSerialization | ||
{ | ||
using System; | ||
|
||
/// <summary>Options that control the serialization process.</summary> | ||
[Flags] | ||
public enum SerializationOptions | ||
{ | ||
/// <summary>Serializes using the default options</summary> | ||
None = 0, | ||
/// <summary> | ||
/// Ensures that it will be possible to deserialize the serialized objects. | ||
/// </summary> | ||
Roundtrip = 1, | ||
/// <summary> | ||
/// If this flag is specified, if the same object appears more than once in the | ||
/// serialization graph, it will be serialized each time instead of just once. | ||
/// </summary> | ||
/// <remarks> | ||
/// If the serialization graph contains circular references and this flag is set, | ||
/// a StackOverflowException will be thrown. | ||
/// If this flag is not set, there is a performance penalty because the entire | ||
/// object graph must be walked twice. | ||
/// </remarks> | ||
DisableAliases = 2, | ||
/// <summary> | ||
/// Forces every value to be serialized, even if it is the default value for that type. | ||
/// </summary> | ||
EmitDefaults = 4, | ||
/// <summary> | ||
/// Ensures that the result of the serialization is valid JSON. | ||
/// </summary> | ||
JsonCompatible = 8, | ||
/// <summary> | ||
/// Use the static type of values instead of their actual type. | ||
/// </summary> | ||
DefaultToStaticType = 16, // 0x00000010 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters