-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathFloatEmitter.cs
33 lines (31 loc) · 1.06 KB
/
FloatEmitter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Globalization;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.EventEmitters;
namespace k8s
{
internal class FloatEmitter : ChainedEventEmitter
{
public FloatEmitter(IEventEmitter nextEmitter)
: base(nextEmitter)
{
}
public override void Emit(ScalarEventInfo eventInfo, IEmitter emitter)
{
switch (eventInfo.Source.Value)
{
// Floating point numbers should always render at least one zero (e.g. 1.0f => '1.0' not '1')
case double d:
emitter.Emit(new Scalar(d.ToString("0.0######################", CultureInfo.InvariantCulture)));
break;
case float f:
emitter.Emit(new Scalar(f.ToString("0.0######################", CultureInfo.InvariantCulture)));
break;
default:
base.Emit(eventInfo, emitter);
break;
}
}
}
}