Skip to content

Commit 5603fa3

Browse files
committed
Regenerate code
1 parent d88e22d commit 5603fa3

File tree

8 files changed

+785
-1035
lines changed

8 files changed

+785
-1035
lines changed

UnitsNet/GeneratedCode/Quantities/BitRate.g.cs

Lines changed: 300 additions & 588 deletions
Large diffs are not rendered by default.

UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs

Lines changed: 103 additions & 115 deletions
Large diffs are not rendered by default.

UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs

Lines changed: 93 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -69,45 +69,70 @@ public sealed partial class MagneticFlux
6969
public partial struct MagneticFlux : IComparable, IComparable<MagneticFlux>
7070
#endif
7171
{
72+
private readonly double _value;
73+
74+
/// <summary>
75+
/// The numeric value this quantity was constructed with.
76+
/// </summary>
77+
#if WINDOWS_UWP
78+
public double Value => Convert.ToDouble(_value);
79+
#else
80+
public double Value => _value;
81+
#endif
82+
7283
/// <summary>
73-
/// Base unit of MagneticFlux.
84+
/// The unit this quantity was constructed with.
7485
/// </summary>
75-
private readonly double _webers;
86+
public MagneticFluxUnit Unit { get; }
7687

7788
// Windows Runtime Component requires a default constructor
7889
#if WINDOWS_UWP
79-
public MagneticFlux() : this(0)
90+
public MagneticFlux() : this(0, BaseUnit)
8091
{
8192
}
8293
#endif
8394

95+
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
8496
public MagneticFlux(double webers)
8597
{
86-
_webers = Convert.ToDouble(webers);
98+
_value = Convert.ToDouble(webers);
99+
Unit = BaseUnit;
87100
}
88101

102+
/// <summary>
103+
/// Creates the quantity with the given numeric value and unit.
104+
/// </summary>
105+
/// <param name="numericValue">Numeric value.</param>
106+
/// <param name="unit">Unit representation.</param>
107+
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
108+
#if WINDOWS_UWP
109+
public MagneticFlux(double numericValue, MagneticFluxUnit unit)
110+
#else
111+
public MagneticFlux(double numericValue, MagneticFluxUnit unit)
112+
#endif
113+
{
114+
_value = numericValue;
115+
Unit = unit;
116+
}
117+
89118
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
90119
#if WINDOWS_UWP
91120
private
92121
#else
122+
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
93123
public
94124
#endif
95-
MagneticFlux(long webers)
96-
{
97-
_webers = Convert.ToDouble(webers);
98-
}
125+
MagneticFlux(long webers) : this(Convert.ToDouble(webers), BaseUnit) { }
99126

100127
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
101128
// Windows Runtime Component does not support decimal type
102129
#if WINDOWS_UWP
103130
private
104131
#else
132+
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
105133
public
106134
#endif
107-
MagneticFlux(decimal webers)
108-
{
109-
_webers = Convert.ToDouble(webers);
110-
}
135+
MagneticFlux(decimal webers) : this(Convert.ToDouble(webers), BaseUnit) { }
111136

112137
#region Properties
113138

@@ -119,50 +144,36 @@ public MagneticFlux(double webers)
119144
/// <summary>
120145
/// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value.
121146
/// </summary>
122-
public static MagneticFluxUnit BaseUnit
123-
{
124-
get { return MagneticFluxUnit.Weber; }
125-
}
147+
public static MagneticFluxUnit BaseUnit => MagneticFluxUnit.Weber;
126148

127149
/// <summary>
128150
/// All units of measurement for the MagneticFlux quantity.
129151
/// </summary>
130152
public static MagneticFluxUnit[] Units { get; } = Enum.GetValues(typeof(MagneticFluxUnit)).Cast<MagneticFluxUnit>().ToArray();
131-
132153
/// <summary>
133154
/// Get MagneticFlux in Webers.
134155
/// </summary>
135-
public double Webers
136-
{
137-
get { return _webers; }
138-
}
156+
public double Webers => As(MagneticFluxUnit.Weber);
139157

140158
#endregion
141159

142160
#region Static
143161

144-
public static MagneticFlux Zero
145-
{
146-
get { return new MagneticFlux(); }
147-
}
162+
public static MagneticFlux Zero => new MagneticFlux(0, BaseUnit);
148163

149164
/// <summary>
150165
/// Get MagneticFlux from Webers.
151166
/// </summary>
152167
#if WINDOWS_UWP
153168
[Windows.Foundation.Metadata.DefaultOverload]
154169
public static MagneticFlux FromWebers(double webers)
155-
{
156-
double value = (double) webers;
157-
return new MagneticFlux(value);
158-
}
159170
#else
160171
public static MagneticFlux FromWebers(QuantityValue webers)
172+
#endif
161173
{
162174
double value = (double) webers;
163-
return new MagneticFlux((value));
175+
return new MagneticFlux(value, MagneticFluxUnit.Weber);
164176
}
165-
#endif
166177

167178
// Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
168179
#if !WINDOWS_UWP
@@ -197,14 +208,7 @@ public static MagneticFlux From(double value, MagneticFluxUnit fromUnit)
197208
public static MagneticFlux From(QuantityValue value, MagneticFluxUnit fromUnit)
198209
#endif
199210
{
200-
switch (fromUnit)
201-
{
202-
case MagneticFluxUnit.Weber:
203-
return FromWebers(value);
204-
205-
default:
206-
throw new NotImplementedException("fromUnit: " + fromUnit);
207-
}
211+
return new MagneticFlux((double)value, fromUnit);
208212
}
209213

210214
// Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -221,14 +225,8 @@ public static MagneticFlux From(QuantityValue value, MagneticFluxUnit fromUnit)
221225
{
222226
return null;
223227
}
224-
switch (fromUnit)
225-
{
226-
case MagneticFluxUnit.Weber:
227-
return FromWebers(value.Value);
228228

229-
default:
230-
throw new NotImplementedException("fromUnit: " + fromUnit);
231-
}
229+
return new MagneticFlux((double)value.Value, fromUnit);
232230
}
233231
#endif
234232

@@ -263,37 +261,37 @@ public static string GetAbbreviation(MagneticFluxUnit unit, [CanBeNull] Culture
263261
#if !WINDOWS_UWP
264262
public static MagneticFlux operator -(MagneticFlux right)
265263
{
266-
return new MagneticFlux(-right._webers);
264+
return new MagneticFlux(-right.Value, right.Unit);
267265
}
268266

269267
public static MagneticFlux operator +(MagneticFlux left, MagneticFlux right)
270268
{
271-
return new MagneticFlux(left._webers + right._webers);
269+
return new MagneticFlux(left.Value + right.AsBaseNumericType(left.Unit), left.Unit);
272270
}
273271

274272
public static MagneticFlux operator -(MagneticFlux left, MagneticFlux right)
275273
{
276-
return new MagneticFlux(left._webers - right._webers);
274+
return new MagneticFlux(left.Value - right.AsBaseNumericType(left.Unit), left.Unit);
277275
}
278276

279277
public static MagneticFlux operator *(double left, MagneticFlux right)
280278
{
281-
return new MagneticFlux(left*right._webers);
279+
return new MagneticFlux(left * right.Value, right.Unit);
282280
}
283281

284282
public static MagneticFlux operator *(MagneticFlux left, double right)
285283
{
286-
return new MagneticFlux(left._webers*(double)right);
284+
return new MagneticFlux(left.Value * right, left.Unit);
287285
}
288286

289287
public static MagneticFlux operator /(MagneticFlux left, double right)
290288
{
291-
return new MagneticFlux(left._webers/(double)right);
289+
return new MagneticFlux(left.Value / right, left.Unit);
292290
}
293291

294292
public static double operator /(MagneticFlux left, MagneticFlux right)
295293
{
296-
return Convert.ToDouble(left._webers/right._webers);
294+
return left.Webers / right.Webers;
297295
}
298296
#endif
299297

@@ -316,43 +314,43 @@ public int CompareTo(object obj)
316314
#endif
317315
int CompareTo(MagneticFlux other)
318316
{
319-
return _webers.CompareTo(other._webers);
317+
return AsBaseUnitWebers().CompareTo(other.AsBaseUnitWebers());
320318
}
321319

322320
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
323321
#if !WINDOWS_UWP
324322
public static bool operator <=(MagneticFlux left, MagneticFlux right)
325323
{
326-
return left._webers <= right._webers;
324+
return left.Value <= right.AsBaseNumericType(left.Unit);
327325
}
328326

329327
public static bool operator >=(MagneticFlux left, MagneticFlux right)
330328
{
331-
return left._webers >= right._webers;
329+
return left.Value >= right.AsBaseNumericType(left.Unit);
332330
}
333331

334332
public static bool operator <(MagneticFlux left, MagneticFlux right)
335333
{
336-
return left._webers < right._webers;
334+
return left.Value < right.AsBaseNumericType(left.Unit);
337335
}
338336

339337
public static bool operator >(MagneticFlux left, MagneticFlux right)
340338
{
341-
return left._webers > right._webers;
339+
return left.Value > right.AsBaseNumericType(left.Unit);
342340
}
343341

344342
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
345343
public static bool operator ==(MagneticFlux left, MagneticFlux right)
346344
{
347345
// ReSharper disable once CompareOfFloatsByEqualityOperator
348-
return left._webers == right._webers;
346+
return left.Value == right.AsBaseNumericType(left.Unit);
349347
}
350348

351349
[Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")]
352350
public static bool operator !=(MagneticFlux left, MagneticFlux right)
353351
{
354352
// ReSharper disable once CompareOfFloatsByEqualityOperator
355-
return left._webers != right._webers;
353+
return left.Value != right.AsBaseNumericType(left.Unit);
356354
}
357355
#endif
358356

@@ -364,7 +362,7 @@ public override bool Equals(object obj)
364362
return false;
365363
}
366364

367-
return _webers.Equals(((MagneticFlux) obj)._webers);
365+
return Value.Equals(((MagneticFlux) obj).AsBaseNumericType(Unit));
368366
}
369367

370368
/// <summary>
@@ -377,12 +375,12 @@ public override bool Equals(object obj)
377375
/// <returns>True if the difference between the two values is not greater than the specified max.</returns>
378376
public bool Equals(MagneticFlux other, MagneticFlux maxError)
379377
{
380-
return Math.Abs(_webers - other._webers) <= maxError._webers;
378+
return Math.Abs(Value - other.AsBaseNumericType(Unit)) <= maxError.AsBaseNumericType(Unit);
381379
}
382380

383381
public override int GetHashCode()
384382
{
385-
return _webers.GetHashCode();
383+
return new { Value, Unit }.GetHashCode();
386384
}
387385

388386
#endregion
@@ -392,14 +390,19 @@ public override int GetHashCode()
392390
/// <summary>
393391
/// Convert to the unit representation <paramref name="unit" />.
394392
/// </summary>
395-
/// <returns>Value in new unit if successful, exception otherwise.</returns>
396-
/// <exception cref="NotImplementedException">If conversion was not successful.</exception>
393+
/// <returns>Value converted to the specified unit.</returns>
397394
public double As(MagneticFluxUnit unit)
398395
{
396+
if (Unit == unit)
397+
{
398+
return (double)Value;
399+
}
400+
401+
double baseUnitValue = AsBaseUnitWebers();
402+
399403
switch (unit)
400404
{
401-
case MagneticFluxUnit.Weber:
402-
return Webers;
405+
case MagneticFluxUnit.Weber: return baseUnitValue;
403406

404407
default:
405408
throw new NotImplementedException("unit: " + unit);
@@ -576,6 +579,7 @@ static MagneticFluxUnit ParseUnit(string str, IFormatProvider formatProvider = n
576579

577580
#endregion
578581

582+
[Obsolete("This should no longer be used. ToString() uses the unit this quantity value was constructed with as default. Pass argument BaseUnit to preserve old behavior.")]
579583
/// <summary>
580584
/// Set the default unit used by ToString(). Default is Weber
581585
/// </summary>
@@ -587,7 +591,7 @@ static MagneticFluxUnit ParseUnit(string str, IFormatProvider formatProvider = n
587591
/// <returns>String representation.</returns>
588592
public override string ToString()
589593
{
590-
return ToString(ToStringDefaultUnit);
594+
return ToString(Unit);
591595
}
592596

593597
/// <summary>
@@ -655,23 +659,31 @@ public string ToString(MagneticFluxUnit unit, [CanBeNull] Culture culture, [NotN
655659
/// <summary>
656660
/// Represents the largest possible value of MagneticFlux
657661
/// </summary>
658-
public static MagneticFlux MaxValue
659-
{
660-
get
661-
{
662-
return new MagneticFlux(double.MaxValue);
663-
}
664-
}
662+
public static MagneticFlux MaxValue => new MagneticFlux(double.MaxValue, BaseUnit);
665663

666664
/// <summary>
667665
/// Represents the smallest possible value of MagneticFlux
668666
/// </summary>
669-
public static MagneticFlux MinValue
667+
public static MagneticFlux MinValue => new MagneticFlux(double.MinValue, BaseUnit);
668+
669+
/// <summary>
670+
/// Converts the current value + unit to the base unit.
671+
/// This is typically the first step in converting from one unit to another.
672+
/// </summary>
673+
/// <returns>The value in the base unit representation.</returns>
674+
private double AsBaseUnitWebers()
670675
{
671-
get
676+
if (Unit == MagneticFluxUnit.Weber) { return _value; }
677+
678+
switch (Unit)
672679
{
673-
return new MagneticFlux(double.MinValue);
674-
}
675-
}
676-
}
680+
case MagneticFluxUnit.Weber: return _value;
681+
default:
682+
throw new NotImplementedException("Unit not implemented: " + Unit);
683+
}
684+
}
685+
686+
/// <summary>Convenience method for working with internal numeric type.</summary>
687+
private double AsBaseNumericType(MagneticFluxUnit unit) => Convert.ToDouble(As(unit));
688+
}
677689
}

0 commit comments

Comments
 (0)