forked from aaubry/YamlDotNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
92 additions
and
22 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
33 changes: 33 additions & 0 deletions
33
YamlDotNet/Serialization/Converters/SystemTypeConverter.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,33 @@ | ||
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 = ((Scalar)parser.Current).Value; | ||
parser.MoveNext(); | ||
return Type.GetType(value, throwOnError: true); | ||
} | ||
|
||
public void WriteYaml(IEmitter emitter, object value, Type type) | ||
{ | ||
var systemType = (Type)value; | ||
emitter.Emit(new Scalar(null, null, systemType.AssemblyQualifiedName, ScalarStyle.Any, true, false)); | ||
} | ||
} | ||
} |
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