diff --git a/YamlDotNet.RepresentationModel/Serialization/JsonEventEmitter.cs b/YamlDotNet.RepresentationModel/Serialization/JsonEventEmitter.cs
new file mode 100644
index 00000000..ee9bd2a8
--- /dev/null
+++ b/YamlDotNet.RepresentationModel/Serialization/JsonEventEmitter.cs
@@ -0,0 +1,90 @@
+using System;
+using System.Globalization;
+using YamlDotNet.Core;
+using YamlDotNet.Core.Events;
+
+namespace YamlDotNet.RepresentationModel.Serialization
+{
+ public sealed class JsonEventEmitter : ChainedEventEmitter
+ {
+ public JsonEventEmitter(IEventEmitter nextEmitter)
+ : base(nextEmitter)
+ {
+ }
+
+ public override void Emit(AliasEventInfo eventInfo)
+ {
+ throw new NotSupportedException("Aliases are not supported in JSON");
+ }
+
+ public override void Emit(ScalarEventInfo eventInfo)
+ {
+ eventInfo.IsPlainImplicit = true;
+ eventInfo.Style = ScalarStyle.Plain;
+
+ var typeCode = eventInfo.SourceValue != null
+ ? Type.GetTypeCode(eventInfo.SourceType)
+ : TypeCode.Empty;
+
+ switch (typeCode)
+ {
+ case TypeCode.Boolean:
+ eventInfo.RenderedValue = YamlFormatter.FormatBoolean(eventInfo.SourceValue);
+ 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:
+ case TypeCode.Single:
+ case TypeCode.Double:
+ case TypeCode.Decimal:
+ eventInfo.RenderedValue = YamlFormatter.FormatNumber(eventInfo.SourceValue);
+ break;
+
+ case TypeCode.String:
+ case TypeCode.Char:
+ eventInfo.RenderedValue = eventInfo.SourceValue.ToString();
+ eventInfo.Style = ScalarStyle.DoubleQuoted;
+ break;
+
+ case TypeCode.DateTime:
+ eventInfo.RenderedValue = YamlFormatter.FormatDateTime(eventInfo.SourceValue);
+ break;
+
+ case TypeCode.Empty:
+ eventInfo.RenderedValue = "null";
+ break;
+
+ default:
+ if (eventInfo.SourceType == typeof(TimeSpan))
+ {
+ eventInfo.RenderedValue = YamlFormatter.FormatTimeSpan(eventInfo.SourceValue);
+ break;
+ }
+
+ throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "TypeCode.{0} is not supported.", typeCode));
+ }
+
+ base.Emit(eventInfo);
+ }
+
+ public override void Emit(MappingStartEventInfo eventInfo)
+ {
+ eventInfo.Style = MappingStyle.Flow;
+
+ base.Emit(eventInfo);
+ }
+
+ public override void Emit(SequenceStartEventInfo eventInfo)
+ {
+ eventInfo.Style = SequenceStyle.Flow;
+
+ base.Emit(eventInfo);
+ }
+ }
+}
\ No newline at end of file
diff --git a/YamlDotNet.RepresentationModel/Serialization/TypeAssigningEventEmitter.cs b/YamlDotNet.RepresentationModel/Serialization/TypeAssigningEventEmitter.cs
index cdc984f9..62861001 100644
--- a/YamlDotNet.RepresentationModel/Serialization/TypeAssigningEventEmitter.cs
+++ b/YamlDotNet.RepresentationModel/Serialization/TypeAssigningEventEmitter.cs
@@ -1,93 +1,9 @@
using System;
using System.Globalization;
using YamlDotNet.Core;
-using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel.Serialization
{
- public sealed class JsonEventEmitter : ChainedEventEmitter
- {
- public JsonEventEmitter(IEventEmitter nextEmitter)
- : base(nextEmitter)
- {
- }
-
- public override void Emit(AliasEventInfo eventInfo)
- {
- throw new NotSupportedException("Aliases are not supported in JSON");
- }
-
- public override void Emit(ScalarEventInfo eventInfo)
- {
- eventInfo.IsPlainImplicit = true;
- eventInfo.Style = ScalarStyle.Plain;
-
- var typeCode = eventInfo.SourceValue != null
- ? Type.GetTypeCode(eventInfo.SourceType)
- : TypeCode.Empty;
-
- switch (typeCode)
- {
- case TypeCode.Boolean:
- eventInfo.RenderedValue = YamlFormatter.FormatBoolean(eventInfo.SourceValue);
- 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:
- case TypeCode.Single:
- case TypeCode.Double:
- case TypeCode.Decimal:
- eventInfo.RenderedValue = YamlFormatter.FormatNumber(eventInfo.SourceValue);
- break;
-
- case TypeCode.String:
- case TypeCode.Char:
- eventInfo.RenderedValue = eventInfo.SourceValue.ToString();
- eventInfo.Style = ScalarStyle.DoubleQuoted;
- break;
-
- case TypeCode.DateTime:
- eventInfo.RenderedValue = YamlFormatter.FormatDateTime(eventInfo.SourceValue);
- break;
-
- case TypeCode.Empty:
- eventInfo.RenderedValue = "null";
- break;
-
- default:
- if (eventInfo.SourceType == typeof(TimeSpan))
- {
- eventInfo.RenderedValue = YamlFormatter.FormatTimeSpan(eventInfo.SourceValue);
- break;
- }
-
- throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "TypeCode.{0} is not supported.", typeCode));
- }
-
- base.Emit(eventInfo);
- }
-
- public override void Emit(MappingStartEventInfo eventInfo)
- {
- eventInfo.Style = MappingStyle.Flow;
-
- base.Emit(eventInfo);
- }
-
- public override void Emit(SequenceStartEventInfo eventInfo)
- {
- eventInfo.Style = SequenceStyle.Flow;
-
- base.Emit(eventInfo);
- }
- }
-
public sealed class TypeAssigningEventEmitter : ChainedEventEmitter
{
public TypeAssigningEventEmitter(IEventEmitter nextEmitter)
@@ -159,42 +75,5 @@ public override void Emit(ScalarEventInfo eventInfo)
base.Emit(eventInfo);
}
-
- }
-
- internal static class YamlFormatter
- {
- private static readonly NumberFormatInfo numberFormat = new NumberFormatInfo
- {
- CurrencyDecimalSeparator = ".",
- CurrencyGroupSeparator = "_",
- CurrencyGroupSizes = new[] { 3 },
- CurrencySymbol = string.Empty,
- CurrencyDecimalDigits = 99,
- NumberDecimalSeparator = ".",
- NumberGroupSeparator = "_",
- NumberGroupSizes = new[] { 3 },
- NumberDecimalDigits = 99
- };
-
- public static string FormatNumber(object number)
- {
- return Convert.ToString(number, numberFormat);
- }
-
- public static string FormatBoolean(object boolean)
- {
- return boolean.Equals(true) ? "true" : "false";
- }
-
- public static string FormatDateTime(object dateTime)
- {
- return ((DateTime)dateTime).ToString("o", CultureInfo.InvariantCulture);
- }
-
- public static string FormatTimeSpan(object timeSpan)
- {
- return ((TimeSpan)timeSpan).ToString();
- }
}
}
\ No newline at end of file
diff --git a/YamlDotNet.RepresentationModel/Serialization/YamlFormatter.cs b/YamlDotNet.RepresentationModel/Serialization/YamlFormatter.cs
new file mode 100644
index 00000000..18802bba
--- /dev/null
+++ b/YamlDotNet.RepresentationModel/Serialization/YamlFormatter.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Globalization;
+
+namespace YamlDotNet.RepresentationModel.Serialization
+{
+ internal static class YamlFormatter
+ {
+ private static readonly NumberFormatInfo numberFormat = new NumberFormatInfo
+ {
+ CurrencyDecimalSeparator = ".",
+ CurrencyGroupSeparator = "_",
+ CurrencyGroupSizes = new[] { 3 },
+ CurrencySymbol = string.Empty,
+ CurrencyDecimalDigits = 99,
+ NumberDecimalSeparator = ".",
+ NumberGroupSeparator = "_",
+ NumberGroupSizes = new[] { 3 },
+ NumberDecimalDigits = 99
+ };
+
+ public static string FormatNumber(object number)
+ {
+ return Convert.ToString(number, numberFormat);
+ }
+
+ public static string FormatBoolean(object boolean)
+ {
+ return boolean.Equals(true) ? "true" : "false";
+ }
+
+ public static string FormatDateTime(object dateTime)
+ {
+ return ((DateTime)dateTime).ToString("o", CultureInfo.InvariantCulture);
+ }
+
+ public static string FormatTimeSpan(object timeSpan)
+ {
+ return ((TimeSpan)timeSpan).ToString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/YamlDotNet.RepresentationModel/YamlDotNet.RepresentationModel.csproj b/YamlDotNet.RepresentationModel/YamlDotNet.RepresentationModel.csproj
index 08fbad32..2c44fd1b 100644
--- a/YamlDotNet.RepresentationModel/YamlDotNet.RepresentationModel.csproj
+++ b/YamlDotNet.RepresentationModel/YamlDotNet.RepresentationModel.csproj
@@ -89,6 +89,7 @@
+
@@ -118,6 +119,7 @@
+