Skip to content

Commit 420c2e3

Browse files
authored
Use generic number type to reduce method overload count (#306)
* Take QuantityValue instead of number types This reduces the current number of overloads to 1/4th. We also get additional number types: float, short, byte * Make ctor private * Explicitly cast QuantityValue to double To avoid too much magic. This is only used internally in generated code anyway. * Regenerate code
1 parent 6e23232 commit 420c2e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8506
-46588
lines changed

UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs

Lines changed: 72 additions & 521 deletions
Large diffs are not rendered by default.

UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs

Lines changed: 242 additions & 1146 deletions
Large diffs are not rendered by default.

UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs

Lines changed: 45 additions & 299 deletions
Large diffs are not rendered by default.

UnitsNet/GeneratedCode/Quantities/Angle.g.cs

Lines changed: 225 additions & 1064 deletions
Large diffs are not rendered by default.

UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs

Lines changed: 36 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -165,114 +165,54 @@ public static ApparentPower Zero
165165
/// <summary>
166166
/// Get ApparentPower from Kilovoltamperes.
167167
/// </summary>
168-
#if NETFX_CORE
168+
#if WINDOWS_UWP
169169
[Windows.Foundation.Metadata.DefaultOverload]
170-
#endif
171170
public static ApparentPower FromKilovoltamperes(double kilovoltamperes)
172171
{
173-
return new ApparentPower((kilovoltamperes) * 1e3d);
174-
}
175-
176-
/// <summary>
177-
/// Get ApparentPower from Kilovoltamperes.
178-
/// </summary>
179-
public static ApparentPower FromKilovoltamperes(int kilovoltamperes)
180-
{
181-
return new ApparentPower((kilovoltamperes) * 1e3d);
182-
}
183-
184-
/// <summary>
185-
/// Get ApparentPower from Kilovoltamperes.
186-
/// </summary>
187-
public static ApparentPower FromKilovoltamperes(long kilovoltamperes)
188-
{
189-
return new ApparentPower((kilovoltamperes) * 1e3d);
172+
double value = (double) kilovoltamperes;
173+
return new ApparentPower((value) * 1e3d);
190174
}
191-
192-
// Windows Runtime Component does not support decimal type
193-
#if !WINDOWS_UWP
194-
/// <summary>
195-
/// Get ApparentPower from Kilovoltamperes of type decimal.
196-
/// </summary>
197-
public static ApparentPower FromKilovoltamperes(decimal kilovoltamperes)
175+
#else
176+
public static ApparentPower FromKilovoltamperes(QuantityValue kilovoltamperes)
198177
{
199-
return new ApparentPower((Convert.ToDouble(kilovoltamperes)) * 1e3d);
178+
double value = (double) kilovoltamperes;
179+
return new ApparentPower(((value) * 1e3d));
200180
}
201181
#endif
202182

203183
/// <summary>
204184
/// Get ApparentPower from Megavoltamperes.
205185
/// </summary>
206-
#if NETFX_CORE
186+
#if WINDOWS_UWP
207187
[Windows.Foundation.Metadata.DefaultOverload]
208-
#endif
209188
public static ApparentPower FromMegavoltamperes(double megavoltamperes)
210189
{
211-
return new ApparentPower((megavoltamperes) * 1e6d);
190+
double value = (double) megavoltamperes;
191+
return new ApparentPower((value) * 1e6d);
212192
}
213-
214-
/// <summary>
215-
/// Get ApparentPower from Megavoltamperes.
216-
/// </summary>
217-
public static ApparentPower FromMegavoltamperes(int megavoltamperes)
218-
{
219-
return new ApparentPower((megavoltamperes) * 1e6d);
220-
}
221-
222-
/// <summary>
223-
/// Get ApparentPower from Megavoltamperes.
224-
/// </summary>
225-
public static ApparentPower FromMegavoltamperes(long megavoltamperes)
226-
{
227-
return new ApparentPower((megavoltamperes) * 1e6d);
228-
}
229-
230-
// Windows Runtime Component does not support decimal type
231-
#if !WINDOWS_UWP
232-
/// <summary>
233-
/// Get ApparentPower from Megavoltamperes of type decimal.
234-
/// </summary>
235-
public static ApparentPower FromMegavoltamperes(decimal megavoltamperes)
193+
#else
194+
public static ApparentPower FromMegavoltamperes(QuantityValue megavoltamperes)
236195
{
237-
return new ApparentPower((Convert.ToDouble(megavoltamperes)) * 1e6d);
196+
double value = (double) megavoltamperes;
197+
return new ApparentPower(((value) * 1e6d));
238198
}
239199
#endif
240200

241201
/// <summary>
242202
/// Get ApparentPower from Voltamperes.
243203
/// </summary>
244-
#if NETFX_CORE
204+
#if WINDOWS_UWP
245205
[Windows.Foundation.Metadata.DefaultOverload]
246-
#endif
247206
public static ApparentPower FromVoltamperes(double voltamperes)
248207
{
249-
return new ApparentPower(voltamperes);
250-
}
251-
252-
/// <summary>
253-
/// Get ApparentPower from Voltamperes.
254-
/// </summary>
255-
public static ApparentPower FromVoltamperes(int voltamperes)
256-
{
257-
return new ApparentPower(voltamperes);
258-
}
259-
260-
/// <summary>
261-
/// Get ApparentPower from Voltamperes.
262-
/// </summary>
263-
public static ApparentPower FromVoltamperes(long voltamperes)
264-
{
265-
return new ApparentPower(voltamperes);
208+
double value = (double) voltamperes;
209+
return new ApparentPower(value);
266210
}
267-
268-
// Windows Runtime Component does not support decimal type
269-
#if !WINDOWS_UWP
270-
/// <summary>
271-
/// Get ApparentPower from Voltamperes of type decimal.
272-
/// </summary>
273-
public static ApparentPower FromVoltamperes(decimal voltamperes)
211+
#else
212+
public static ApparentPower FromVoltamperes(QuantityValue voltamperes)
274213
{
275-
return new ApparentPower(Convert.ToDouble(voltamperes));
214+
double value = (double) voltamperes;
215+
return new ApparentPower((value));
276216
}
277217
#endif
278218

@@ -281,7 +221,7 @@ public static ApparentPower FromVoltamperes(decimal voltamperes)
281221
/// <summary>
282222
/// Get nullable ApparentPower from nullable Kilovoltamperes.
283223
/// </summary>
284-
public static ApparentPower? FromKilovoltamperes(double? kilovoltamperes)
224+
public static ApparentPower? FromKilovoltamperes(QuantityValue? kilovoltamperes)
285225
{
286226
if (kilovoltamperes.HasValue)
287227
{
@@ -293,70 +233,10 @@ public static ApparentPower FromVoltamperes(decimal voltamperes)
293233
}
294234
}
295235

296-
/// <summary>
297-
/// Get nullable ApparentPower from nullable Kilovoltamperes.
298-
/// </summary>
299-
public static ApparentPower? FromKilovoltamperes(int? kilovoltamperes)
300-
{
301-
if (kilovoltamperes.HasValue)
302-
{
303-
return FromKilovoltamperes(kilovoltamperes.Value);
304-
}
305-
else
306-
{
307-
return null;
308-
}
309-
}
310-
311-
/// <summary>
312-
/// Get nullable ApparentPower from nullable Kilovoltamperes.
313-
/// </summary>
314-
public static ApparentPower? FromKilovoltamperes(long? kilovoltamperes)
315-
{
316-
if (kilovoltamperes.HasValue)
317-
{
318-
return FromKilovoltamperes(kilovoltamperes.Value);
319-
}
320-
else
321-
{
322-
return null;
323-
}
324-
}
325-
326-
/// <summary>
327-
/// Get nullable ApparentPower from Kilovoltamperes of type decimal.
328-
/// </summary>
329-
public static ApparentPower? FromKilovoltamperes(decimal? kilovoltamperes)
330-
{
331-
if (kilovoltamperes.HasValue)
332-
{
333-
return FromKilovoltamperes(kilovoltamperes.Value);
334-
}
335-
else
336-
{
337-
return null;
338-
}
339-
}
340-
341-
/// <summary>
342-
/// Get nullable ApparentPower from nullable Megavoltamperes.
343-
/// </summary>
344-
public static ApparentPower? FromMegavoltamperes(double? megavoltamperes)
345-
{
346-
if (megavoltamperes.HasValue)
347-
{
348-
return FromMegavoltamperes(megavoltamperes.Value);
349-
}
350-
else
351-
{
352-
return null;
353-
}
354-
}
355-
356236
/// <summary>
357237
/// Get nullable ApparentPower from nullable Megavoltamperes.
358238
/// </summary>
359-
public static ApparentPower? FromMegavoltamperes(int? megavoltamperes)
239+
public static ApparentPower? FromMegavoltamperes(QuantityValue? megavoltamperes)
360240
{
361241
if (megavoltamperes.HasValue)
362242
{
@@ -368,85 +248,10 @@ public static ApparentPower FromVoltamperes(decimal voltamperes)
368248
}
369249
}
370250

371-
/// <summary>
372-
/// Get nullable ApparentPower from nullable Megavoltamperes.
373-
/// </summary>
374-
public static ApparentPower? FromMegavoltamperes(long? megavoltamperes)
375-
{
376-
if (megavoltamperes.HasValue)
377-
{
378-
return FromMegavoltamperes(megavoltamperes.Value);
379-
}
380-
else
381-
{
382-
return null;
383-
}
384-
}
385-
386-
/// <summary>
387-
/// Get nullable ApparentPower from Megavoltamperes of type decimal.
388-
/// </summary>
389-
public static ApparentPower? FromMegavoltamperes(decimal? megavoltamperes)
390-
{
391-
if (megavoltamperes.HasValue)
392-
{
393-
return FromMegavoltamperes(megavoltamperes.Value);
394-
}
395-
else
396-
{
397-
return null;
398-
}
399-
}
400-
401-
/// <summary>
402-
/// Get nullable ApparentPower from nullable Voltamperes.
403-
/// </summary>
404-
public static ApparentPower? FromVoltamperes(double? voltamperes)
405-
{
406-
if (voltamperes.HasValue)
407-
{
408-
return FromVoltamperes(voltamperes.Value);
409-
}
410-
else
411-
{
412-
return null;
413-
}
414-
}
415-
416-
/// <summary>
417-
/// Get nullable ApparentPower from nullable Voltamperes.
418-
/// </summary>
419-
public static ApparentPower? FromVoltamperes(int? voltamperes)
420-
{
421-
if (voltamperes.HasValue)
422-
{
423-
return FromVoltamperes(voltamperes.Value);
424-
}
425-
else
426-
{
427-
return null;
428-
}
429-
}
430-
431251
/// <summary>
432252
/// Get nullable ApparentPower from nullable Voltamperes.
433253
/// </summary>
434-
public static ApparentPower? FromVoltamperes(long? voltamperes)
435-
{
436-
if (voltamperes.HasValue)
437-
{
438-
return FromVoltamperes(voltamperes.Value);
439-
}
440-
else
441-
{
442-
return null;
443-
}
444-
}
445-
446-
/// <summary>
447-
/// Get nullable ApparentPower from Voltamperes of type decimal.
448-
/// </summary>
449-
public static ApparentPower? FromVoltamperes(decimal? voltamperes)
254+
public static ApparentPower? FromVoltamperes(QuantityValue? voltamperes)
450255
{
451256
if (voltamperes.HasValue)
452257
{
@@ -463,19 +268,25 @@ public static ApparentPower FromVoltamperes(decimal voltamperes)
463268
/// <summary>
464269
/// Dynamically convert from value and unit enum <see cref="ApparentPowerUnit" /> to <see cref="ApparentPower" />.
465270
/// </summary>
466-
/// <param name="val">Value to convert from.</param>
271+
/// <param name="value">Value to convert from.</param>
467272
/// <param name="fromUnit">Unit to convert from.</param>
468273
/// <returns>ApparentPower unit value.</returns>
469-
public static ApparentPower From(double val, ApparentPowerUnit fromUnit)
274+
#if WINDOWS_UWP
275+
// Fix name conflict with parameter "value"
276+
[return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
277+
public static ApparentPower From(double value, ApparentPowerUnit fromUnit)
278+
#else
279+
public static ApparentPower From(QuantityValue value, ApparentPowerUnit fromUnit)
280+
#endif
470281
{
471282
switch (fromUnit)
472283
{
473284
case ApparentPowerUnit.Kilovoltampere:
474-
return FromKilovoltamperes(val);
285+
return FromKilovoltamperes(value);
475286
case ApparentPowerUnit.Megavoltampere:
476-
return FromMegavoltamperes(val);
287+
return FromMegavoltamperes(value);
477288
case ApparentPowerUnit.Voltampere:
478-
return FromVoltamperes(val);
289+
return FromVoltamperes(value);
479290

480291
default:
481292
throw new NotImplementedException("fromUnit: " + fromUnit);
@@ -490,7 +301,7 @@ public static ApparentPower From(double val, ApparentPowerUnit fromUnit)
490301
/// <param name="value">Value to convert from.</param>
491302
/// <param name="fromUnit">Unit to convert from.</param>
492303
/// <returns>ApparentPower unit value.</returns>
493-
public static ApparentPower? From(double? value, ApparentPowerUnit fromUnit)
304+
public static ApparentPower? From(QuantityValue? value, ApparentPowerUnit fromUnit)
494305
{
495306
if (!value.HasValue)
496307
{

0 commit comments

Comments
 (0)