* Support round-trip CRD (de)serialization * Add a floating point emitter to fix UT * Unused using * Stylecop * Reduce warnings
33 lines
997 B
C#
33 lines
997 B
C#
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######################")));
|
|
break;
|
|
case float f:
|
|
emitter.Emit(new Scalar(f.ToString("0.0######################")));
|
|
break;
|
|
default:
|
|
base.Emit(eventInfo, emitter);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|