Files
csharp/src/KubernetesClient/Models/ResourceQuantityYamlConverter.cs
Boshi Lian 292262755a revert change to structs from classes for IntOrString and ResourceQuantity, and handle null values in YAML converters (#1673)
* 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
2025-10-15 08:59:35 -07:00

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()));
}
}
}