-
Notifications
You must be signed in to change notification settings - Fork 309
migrate to record #1665
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
migrate to record #1665
Changes from 6 commits
0dfabb7
638f614
04d7445
ff80688
0bd43e4
f695e4b
c1a7c99
a20419b
62b20a6
d4c548a
daa7870
0304920
cfae034
9e986c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// IntOrString.cs(7,36): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported | ||
namespace System.Runtime.CompilerServices | ||
{ | ||
internal static class IsExternalInit { } | ||
Check warning on line 4 in src/KubernetesClient.Classic/IsExternalInit.cs
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||
using System.Globalization; | ||||||
|
||||||
namespace k8s.Models | ||||||
{ | ||||||
[JsonConverter(typeof(IntOrStringJsonConverter))] | ||||||
public struct IntOrString | ||||||
{ | ||||||
public string Value { get; private init; } | ||||||
|
||||||
public static implicit operator IntOrString(int v) | ||||||
{ | ||||||
return Convert.ToString(v); | ||||||
} | ||||||
|
||||||
public static implicit operator IntOrString(long v) | ||||||
{ | ||||||
return Convert.ToString(v); | ||||||
} | ||||||
|
||||||
public static implicit operator string(IntOrString v) | ||||||
{ | ||||||
return v.Value; | ||||||
} | ||||||
|
||||||
public static implicit operator IntOrString(string v) | ||||||
{ | ||||||
return new IntOrString { Value = v }; | ||||||
} | ||||||
|
||||||
public override string ToString() | ||||||
{ | ||||||
return Value; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ToString() can return null when Value is null, which may cause issues for consumers expecting a non-null string. Consider returning string.Empty or a default value when Value is null.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} | ||||||
|
||||||
public int ToInt() | ||||||
{ | ||||||
return int.Parse(Value, CultureInfo.InvariantCulture); | ||||||
tg123 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tg123 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
} | ||||||
} | ||||||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ namespace k8s.Models | |
/// cause implementors to also use a fixed point implementation. | ||
/// </summary> | ||
[JsonConverter(typeof(ResourceQuantityJsonConverter))] | ||
public partial class ResourceQuantity | ||
public struct ResourceQuantity | ||
{ | ||
public enum SuffixFormat | ||
{ | ||
|
@@ -97,39 +97,6 @@ public override string ToString() | |
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); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
return ((int)Format * 397) ^ _unitlessValue.GetHashCode(); | ||
} | ||
} | ||
|
||
// | ||
// CanonicalizeString = go version CanonicalizeBytes | ||
// CanonicalizeBytes returns the canonical form of q and its suffix (see comment on Quantity). | ||
|
@@ -157,18 +124,17 @@ public string CanonicalizeString(SuffixFormat suffixFormat) | |
return Suffixer.AppendMaxSuffix(_unitlessValue, suffixFormat); | ||
} | ||
|
||
// ctor | ||
partial void CustomInit() | ||
public ResourceQuantity(string v) | ||
{ | ||
if (Value == null) | ||
if (v == null) | ||
{ | ||
// No value has been defined, initialize to 0. | ||
_unitlessValue = new Fraction(0); | ||
Format = SuffixFormat.BinarySI; | ||
return; | ||
} | ||
|
||
var value = Value.Trim(); | ||
var value = v.Trim(); | ||
|
||
var si = value.IndexOfAny(SuffixChars); | ||
if (si == -1) | ||
|
@@ -188,6 +154,11 @@ partial void CustomInit() | |
} | ||
} | ||
|
||
public static implicit operator ResourceQuantity(string v) | ||
{ | ||
return new ResourceQuantity(v); | ||
} | ||
|
||
private static bool HasMantissa(Fraction value) | ||
{ | ||
if (value.IsZero) | ||
|
@@ -200,7 +171,7 @@ private static bool HasMantissa(Fraction value) | |
|
||
public static implicit operator decimal(ResourceQuantity v) | ||
{ | ||
tg123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return v?.ToDecimal() ?? 0; | ||
return v.ToDecimal(); | ||
} | ||
Comment on lines
172
to
175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implicit operator calls ToDecimal() on a struct that could be in an uninitialized state. Since ResourceQuantity is now a struct, accessing _unitlessValue when uninitialized could cause issues. Consider adding null/default checks. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
public static implicit operator ResourceQuantity(decimal v) | ||
|
Uh oh!
There was an error while loading. Please reload this page.