Skip to content

Commit 51853ef

Browse files
committed
fix: change structs to classes for IntOrString and ResourceQuantity, and handle null values in YAML converters
1 parent 008025d commit 51853ef

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/KubernetesClient/Models/IntOrString.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace k8s.Models
22
{
33
[JsonConverter(typeof(IntOrStringJsonConverter))]
4-
public struct IntOrString
4+
public class IntOrString
55
{
6-
public string? Value { get; private init; }
6+
public string Value { get; private init; }
77

88
public static implicit operator IntOrString(int v)
99
{
@@ -17,7 +17,7 @@ public static implicit operator IntOrString(long v)
1717

1818
public static implicit operator string(IntOrString v)
1919
{
20-
return v.Value;
20+
return v?.Value;
2121
}
2222

2323
public static implicit operator IntOrString(string v)

src/KubernetesClient/Models/IntOrStringYamlConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
3535
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
3636
{
3737
var obj = (IntOrString)value;
38-
emitter?.Emit(new YamlDotNet.Core.Events.Scalar(obj.Value));
38+
emitter?.Emit(new YamlDotNet.Core.Events.Scalar(obj?.Value));
3939
}
4040
}
4141
}

src/KubernetesClient/Models/ResourceQuantity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace k8s.Models
5454
/// cause implementors to also use a fixed point implementation.
5555
/// </summary>
5656
[JsonConverter(typeof(ResourceQuantityJsonConverter))]
57-
public struct ResourceQuantity
57+
public class ResourceQuantity
5858
{
5959
public enum SuffixFormat
6060
{

src/KubernetesClient/Models/ResourceQuantityYamlConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
3535
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
3636
{
3737
var obj = (ResourceQuantity)value;
38-
emitter?.Emit(new YamlDotNet.Core.Events.Scalar(obj.ToString()));
38+
emitter?.Emit(new YamlDotNet.Core.Events.Scalar(obj?.ToString()));
3939
}
4040
}
4141
}

0 commit comments

Comments
 (0)