@@ -54,7 +54,7 @@ namespace k8s.Models
54
54
/// cause implementors to also use a fixed point implementation.
55
55
/// </summary>
56
56
[ JsonConverter ( typeof ( ResourceQuantityJsonConverter ) ) ]
57
- public partial class ResourceQuantity
57
+ public record ResourceQuantity
58
58
{
59
59
public enum SuffixFormat
60
60
{
@@ -85,12 +85,6 @@ public ResourceQuantity(decimal n, int exp, SuffixFormat format)
85
85
Format = format ;
86
86
}
87
87
88
- public ResourceQuantity ( string s )
89
- {
90
- Value = s ;
91
- CustomInit ( ) ;
92
- }
93
-
94
88
public SuffixFormat Format { get ; private set ; }
95
89
96
90
public string CanonicalizeString ( )
@@ -103,39 +97,6 @@ public override string ToString()
103
97
return CanonicalizeString ( ) ;
104
98
}
105
99
106
- protected bool Equals ( ResourceQuantity other )
107
- {
108
- return _unitlessValue . Equals ( other ? . _unitlessValue ) ;
109
- }
110
-
111
- public override bool Equals ( object obj )
112
- {
113
- if ( ReferenceEquals ( null , obj ) )
114
- {
115
- return false ;
116
- }
117
-
118
- if ( ReferenceEquals ( this , obj ) )
119
- {
120
- return true ;
121
- }
122
-
123
- if ( obj . GetType ( ) != GetType ( ) )
124
- {
125
- return false ;
126
- }
127
-
128
- return Equals ( ( ResourceQuantity ) obj ) ;
129
- }
130
-
131
- public override int GetHashCode ( )
132
- {
133
- unchecked
134
- {
135
- return ( ( int ) Format * 397 ) ^ _unitlessValue . GetHashCode ( ) ;
136
- }
137
- }
138
-
139
100
//
140
101
// CanonicalizeString = go version CanonicalizeBytes
141
102
// CanonicalizeBytes returns the canonical form of q and its suffix (see comment on Quantity).
@@ -163,18 +124,17 @@ public string CanonicalizeString(SuffixFormat suffixFormat)
163
124
return Suffixer . AppendMaxSuffix ( _unitlessValue , suffixFormat ) ;
164
125
}
165
126
166
- // ctor
167
- partial void CustomInit ( )
127
+ public ResourceQuantity ( string v )
168
128
{
169
- if ( Value == null )
129
+ if ( v == null )
170
130
{
171
131
// No value has been defined, initialize to 0.
172
132
_unitlessValue = new Fraction ( 0 ) ;
173
133
Format = SuffixFormat . BinarySI ;
174
134
return ;
175
135
}
176
136
177
- var value = Value . Trim ( ) ;
137
+ var value = v . Trim ( ) ;
178
138
179
139
var si = value . IndexOfAny ( SuffixChars ) ;
180
140
if ( si == - 1 )
@@ -194,6 +154,11 @@ partial void CustomInit()
194
154
}
195
155
}
196
156
157
+ public static implicit operator ResourceQuantity ( string v )
158
+ {
159
+ return new ResourceQuantity ( v ) ;
160
+ }
161
+
197
162
private static bool HasMantissa ( Fraction value )
198
163
{
199
164
if ( value . IsZero )
0 commit comments