Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrating to record for data objects #1549

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/customResource/cResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CResourceSpec
public string CityName { get; set; }
}

public class CResourceStatus : V1Status
public record CResourceStatus : V1Status
{
[JsonPropertyName("temperature")]
public string Temperature { get; set; }
Expand Down
50 changes: 25 additions & 25 deletions src/KubernetesClient/Models/IntstrIntOrString.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace k8s.Models
{
[JsonConverter(typeof(IntOrStringJsonConverter))]
public partial class IntstrIntOrString
public partial record IntstrIntOrString
{
public static implicit operator IntstrIntOrString(int v)
{
Expand All @@ -23,30 +23,30 @@
return new IntstrIntOrString(v);
}

protected bool Equals(IntstrIntOrString other)
{
return string.Equals(Value, other?.Value);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != GetType())
{
return false;
}

return Equals((IntstrIntOrString)obj);
}
//protected bool Equals(IntstrIntOrString other)

Check warning on line 26 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 26 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 26 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 26 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

//{

Check warning on line 27 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 27 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 27 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 27 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

// return string.Equals(Value, other?.Value);
//}

Check warning on line 29 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 29 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 29 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 29 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e


//public override bool Equals(object obj)

Check warning on line 31 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 31 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 31 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 31 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

//V1Status{

Check warning on line 32 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 32 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 32 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 32 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

// if (ReferenceEquals(null, obj))
// {
// return false;
// }

// if (ReferenceEquals(this, obj))

Check warning on line 38 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 38 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 38 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 38 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

// {
// return true;
// }

// if (obj.GetType() != GetType())

Check warning on line 43 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 43 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 43 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 43 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

// {
// return false;
// }

// return Equals((IntstrIntOrString)obj);

Check warning on line 48 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 48 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 48 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 48 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

//}

Check warning on line 49 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 49 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 49 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 49 in src/KubernetesClient/Models/IntstrIntOrString.cs

View workflow job for this annotation

GitHub Actions / e2e


public override int GetHashCode()
{
Expand Down
50 changes: 25 additions & 25 deletions src/KubernetesClient/Models/ResourceQuantity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
/// cause implementors to also use a fixed point implementation.
/// </summary>
[JsonConverter(typeof(ResourceQuantityJsonConverter))]
public partial class ResourceQuantity
public partial record ResourceQuantity
{
public enum SuffixFormat
{
Expand Down Expand Up @@ -97,30 +97,30 @@
return CanonicalizeString();
}

protected bool Equals(ResourceQuantity other)
{
return _unitlessValue.Equals(other?._unitlessValue);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != GetType())
{
return false;
}

return Equals((ResourceQuantity)obj);
}
//protected bool Equals(ResourceQuantity other)

Check warning on line 100 in src/KubernetesClient/Models/ResourceQuantity.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 100 in src/KubernetesClient/Models/ResourceQuantity.cs

View workflow job for this annotation

GitHub Actions / MSBuild build

Check warning on line 100 in src/KubernetesClient/Models/ResourceQuantity.cs

View workflow job for this annotation

GitHub Actions / e2e

Check warning on line 100 in src/KubernetesClient/Models/ResourceQuantity.cs

View workflow job for this annotation

GitHub Actions / e2e

//{
// return _unitlessValue.Equals(other?._unitlessValue);
//}

//public override bool Equals(object obj)
//{
// if (ReferenceEquals(null, obj))
// {
// return false;
// }

// if (ReferenceEquals(this, obj))
// {
// return true;
// }

// if (obj.GetType() != GetType())
// {
// return false;
// }

// return Equals((ResourceQuantity)obj);
//}

public override int GetHashCode()
{
Expand Down
2 changes: 1 addition & 1 deletion src/KubernetesClient/Models/V1Patch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace k8s.Models
{
[JsonConverter(typeof(V1PatchJsonConverter))]
public partial class V1Patch
public partial record V1Patch
{
public enum PatchType
{
Expand Down
2 changes: 1 addition & 1 deletion src/KubernetesClient/Models/V1PodTemplateSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace k8s.Models
/// Partial implementation of the IMetadata interface
/// to open this class up to ModelExtensions methods
/// </summary>
public partial class V1PodTemplateSpec : IMetadata<V1ObjectMeta>
public partial record V1PodTemplateSpec : IMetadata<V1ObjectMeta>
{
}
}
2 changes: 1 addition & 1 deletion src/KubernetesClient/Models/V1Status.ObjectView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace k8s.Models
{
public partial class V1Status
public partial record V1Status
{
internal sealed class V1StatusObjectViewConverter : JsonConverter<V1Status>
{
Expand Down
2 changes: 1 addition & 1 deletion src/KubernetesClient/Models/V1Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace k8s.Models
{
public partial class V1Status
public partial record V1Status
{
/// <summary>Converts a <see cref="V1Status"/> object into a short description of the status.</summary>
/// <returns>string description of the status</returns>
Expand Down
4 changes: 2 additions & 2 deletions src/LibKubernetesGenerator/VersionConverterStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ namespace k8s.Models;
foreach (var (t0, t1) in typePairs)
{
sbmodel.AppendLine($@"
public partial class {t0}
public partial record {t0}
{{
public static explicit operator {t0}({t1} s) => ModelVersionConverter.Convert<{t1}, {t0}>(s);
}}
public partial class {t1}
public partial record {t1}
{{
public static explicit operator {t1}({t0} s) => ModelVersionConverter.Convert<{t0}, {t1}>(s);
}}");
Expand Down
2 changes: 1 addition & 1 deletion src/LibKubernetesGenerator/templates/Model.cs.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace k8s.Models
/// <summary>
/// {{ToXmlDoc def.description}}
/// </summary>
public partial class {{clz}}
public partial record {{clz}}
{
/// <summary>
/// Initializes a new instance of the {{GetClassName def}} class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace k8s.Models
{
{{ for definition in definitions }}
[KubernetesEntity(Group=KubeGroup, Kind=KubeKind, ApiVersion=KubeApiVersion, PluralName=KubePluralName)]
public partial class {{ GetClassName definition }} : {{ GetInterfaceName definition }}
public partial record {{ GetClassName definition }} : {{ GetInterfaceName definition }}
{
public const string KubeApiVersion = "{{ GetApiVersion definition }}";
public const string KubeKind = "{{ GetKind definition }}";
Expand Down
2 changes: 1 addition & 1 deletion tests/KubernetesClient.Tests/KubernetesYamlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void LoadAllFromString()
}

#pragma warning disable CA1812 // Class is used for YAML deserialization tests
private class MyPod : V1Pod
private record MyPod : V1Pod
{
}
#pragma warning restore CA1812
Expand Down
Loading