* feat: add V2HorizontalPodAutoscaler integration test * fix: change structs to classes for IntOrString and ResourceQuantity, and handle null values in YAML converters * feat: implement equality members for ResourceQuantity class
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using YamlDotNet.Core;
|
|
using YamlDotNet.Serialization;
|
|
|
|
namespace k8s.Models
|
|
{
|
|
public class ResourceQuantityYamlConverter : IYamlTypeConverter
|
|
{
|
|
public bool Accepts(Type type)
|
|
{
|
|
return type == typeof(ResourceQuantity);
|
|
}
|
|
|
|
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
|
{
|
|
if (parser?.Current is YamlDotNet.Core.Events.Scalar scalar)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(scalar?.Value))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return scalar?.Value;
|
|
}
|
|
finally
|
|
{
|
|
parser?.MoveNext();
|
|
}
|
|
}
|
|
|
|
throw new InvalidOperationException(parser?.Current?.ToString());
|
|
}
|
|
|
|
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
|
|
{
|
|
var obj = (ResourceQuantity)value;
|
|
emitter?.Emit(new YamlDotNet.Core.Events.Scalar(obj?.ToString()));
|
|
}
|
|
}
|
|
}
|