Skip to content

Commit 702117c

Browse files
committed
uwp: Add conditionals to CustomCode
Exclude operator overloads Use sealed class instead of struct Extract extensions code to separate files
1 parent 903563c commit 702117c

27 files changed

+272
-147
lines changed

UnitsNet.Tests/CustomCode/AmplitudeRatioTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
using System;
2323
using NUnit.Framework;
24+
using UnitsNet.CustomCode.Extensions;
2425

2526
namespace UnitsNet.Tests.CustomCode
2627
{

UnitsNet.Tests/CustomCode/PowerRatioTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
using System;
2323
using NUnit.Framework;
24+
using UnitsNet.CustomCode.Extensions;
2425

2526
namespace UnitsNet.Tests.CustomCode
2627
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace UnitsNet.CustomCode.Extensions
2+
{
3+
/// <summary>
4+
/// Extension methods for <see cref="AmplitudeRatio" />.
5+
/// </summary>
6+
public static class AmplitudeRatioExtensions
7+
{
8+
/// <summary>
9+
/// Gets an <see cref="ElectricPotential" /> from <see cref="AmplitudeRatio" />.
10+
/// </summary>
11+
/// <paramref name="amplitudeRatio">The amplitude ratio to convert.</paramref>
12+
/// <remarks>
13+
/// Provides a nicer syntax for converting an amplitude ratio back to a voltage.
14+
/// <example>
15+
/// <c>var voltage = voltageRatio.ToElectricPotential();</c>
16+
/// </example>
17+
/// </remarks>
18+
public static ElectricPotential ToElectricPotential(this AmplitudeRatio amplitudeRatio)
19+
{
20+
return AmplitudeRatio.ToElectricPotential(amplitudeRatio);
21+
}
22+
23+
/// <summary>
24+
/// Converts a <see cref="AmplitudeRatio" /> to a <see cref="PowerRatio" />.
25+
/// </summary>
26+
/// <param name="amplitudeRatio">The amplitude ratio to convert.</param>
27+
/// <param name="impedance">The input impedance of the load. This is usually 50, 75 or 600 ohms.</param>
28+
/// <remarks>http://www.maximintegrated.com/en/app-notes/index.mvp/id/808</remarks>
29+
public static PowerRatio ToPowerRatio(this AmplitudeRatio amplitudeRatio, ElectricResistance impedance)
30+
{
31+
return AmplitudeRatio.ToPowerRatio(amplitudeRatio, impedance);
32+
}
33+
}
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace UnitsNet.CustomCode.Extensions
2+
{
3+
/// <summary>
4+
/// Extension methods for <see cref="ElectricPotential" />.
5+
/// </summary>
6+
public static class ElectricPotentialExtensions
7+
{
8+
/// <summary>
9+
/// Gets an <see cref="AmplitudeRatio" /> in decibels (dB) relative to 1 volt RMS from an
10+
/// <see cref="ElectricPotential" />.
11+
/// </summary>
12+
/// <remarks>
13+
/// Provides a nicer syntax for converting a voltage to an amplitude ratio (relative to 1 volt RMS).
14+
/// <example>
15+
/// <c>var voltageRatio = voltage.ToAmplitudeRatio();</c>
16+
/// </example>
17+
/// </remarks>
18+
public static AmplitudeRatio ToAmplitudeRatio(this ElectricPotential voltage)
19+
{
20+
return AmplitudeRatio.FromElectricPotential(voltage);
21+
}
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace UnitsNet.CustomCode.Extensions
2+
{
3+
/// <summary>
4+
/// Extension methods for <see cref="Power" />.
5+
/// </summary>
6+
public static class PowerExtensions
7+
{
8+
/// <summary>
9+
/// Gets a <see cref="PowerRatio" /> from a <see cref="Power" /> relative to one watt.
10+
/// </summary>
11+
/// <remarks>
12+
/// Provides a nicer syntax for converting a power to a power ratio (relative to 1 watt).
13+
/// <example>
14+
/// <c>var powerRatio = power.ToPowerRatio();</c>
15+
/// </example>
16+
/// </remarks>
17+
public static PowerRatio ToPowerRatio(this Power power)
18+
{
19+
return PowerRatio.FromPower(power);
20+
}
21+
}
22+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace UnitsNet.CustomCode.Extensions
2+
{
3+
/// <summary>
4+
/// Extension methods for <see cref="PowerRatio" />.
5+
/// </summary>
6+
public static class PowerRatioExtensions
7+
{
8+
/// <summary>
9+
/// Gets a <see cref="Power" /> from a <see cref="PowerRatio" />.
10+
/// </summary>
11+
/// <remarks>
12+
/// Provides a nicer syntax for converting a power ratio back to a power.
13+
/// <example>
14+
/// <c>var power = powerRatio.ToPower();</c>
15+
/// </example>
16+
/// </remarks>
17+
public static Power ToPower(this PowerRatio powerRatio)
18+
{
19+
return PowerRatio.ToPower(powerRatio);
20+
}
21+
22+
/// <summary>
23+
/// Gets a <see cref="AmplitudeRatio" /> from a <see cref="PowerRatio" />.
24+
/// </summary>
25+
/// <param name="powerRatio">The power ratio.</param>
26+
/// <param name="impedance">The input impedance of the load. This is usually 50, 75 or 600 ohms.</param>
27+
public static AmplitudeRatio ToAmplitudeRatio(this PowerRatio powerRatio, ElectricResistance impedance)
28+
{
29+
return PowerRatio.ToAmplitudeRatio(powerRatio, impedance);
30+
}
31+
}
32+
}

UnitsNet/CustomCode/UnitClasses/AmplitudeRatio.extra.cs

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,60 +23,11 @@
2323

2424
namespace UnitsNet
2525
{
26-
/// <summary>
27-
/// Extension methods for <see cref="AmplitudeRatio" />.
28-
/// </summary>
29-
public static class AmplitudeRatioExtensions
30-
{
31-
/// <summary>
32-
/// Gets an <see cref="ElectricPotential" /> from <see cref="AmplitudeRatio" />.
33-
/// </summary>
34-
/// <paramref name="amplitudeRatio">The amplitude ratio to convert.</paramref>
35-
/// <remarks>
36-
/// Provides a nicer syntax for converting an amplitude ratio back to a voltage.
37-
/// <example>
38-
/// <c>var voltage = voltageRatio.ToElectricPotential();</c>
39-
/// </example>
40-
/// </remarks>
41-
public static ElectricPotential ToElectricPotential(this AmplitudeRatio amplitudeRatio)
42-
{
43-
return AmplitudeRatio.ToElectricPotential(amplitudeRatio);
44-
}
45-
46-
/// <summary>
47-
/// Converts a <see cref="AmplitudeRatio" /> to a <see cref="PowerRatio" />.
48-
/// </summary>
49-
/// <param name="amplitudeRatio">The amplitude ratio to convert.</param>
50-
/// <param name="impedance">The input impedance of the load. This is usually 50, 75 or 600 ohms.</param>
51-
/// <remarks>http://www.maximintegrated.com/en/app-notes/index.mvp/id/808</remarks>
52-
public static PowerRatio ToPowerRatio(this AmplitudeRatio amplitudeRatio, ElectricResistance impedance)
53-
{
54-
return AmplitudeRatio.ToPowerRatio(amplitudeRatio, impedance);
55-
}
56-
}
57-
58-
/// <summary>
59-
/// Extension methods for <see cref="ElectricPotential" />.
60-
/// </summary>
61-
public static class ElectricPotentialExtensions
62-
{
63-
/// <summary>
64-
/// Gets an <see cref="AmplitudeRatio" /> in decibels (dB) relative to 1 volt RMS from an
65-
/// <see cref="ElectricPotential" />.
66-
/// </summary>
67-
/// <remarks>
68-
/// Provides a nicer syntax for converting a voltage to an amplitude ratio (relative to 1 volt RMS).
69-
/// <example>
70-
/// <c>var voltageRatio = voltage.ToAmplitudeRatio();</c>
71-
/// </example>
72-
/// </remarks>
73-
public static AmplitudeRatio ToAmplitudeRatio(this ElectricPotential voltage)
74-
{
75-
return AmplitudeRatio.FromElectricPotential(voltage);
76-
}
77-
}
78-
26+
#if WINDOWS_UWP
27+
public sealed partial class AmplitudeRatio
28+
#else
7929
public partial struct AmplitudeRatio
30+
#endif
8031
{
8132
/// <summary>
8233
/// Initializes a new instance of the <see cref="AmplitudeRatio" /> struct from the specified electric potential
@@ -85,7 +36,13 @@ public partial struct AmplitudeRatio
8536
/// resistance.
8637
/// </summary>
8738
/// <param name="voltage">The electric potential referenced to one volt.</param>
88-
public AmplitudeRatio(ElectricPotential voltage)
39+
// Operator overloads not supported in Universal Windows Platform (WinRT Components)
40+
#if WINDOWS_UWP
41+
internal
42+
#else
43+
public
44+
#endif
45+
AmplitudeRatio(ElectricPotential voltage)
8946
: this()
9047
{
9148
if (voltage.Volts <= 0)
@@ -94,7 +51,7 @@ public AmplitudeRatio(ElectricPotential voltage)
9451
"The base-10 logarithm of a number ≤ 0 is undefined. Voltage must be greater than 0 V.");
9552

9653
// E(dBV) = 20*log10(value(V)/reference(V))
97-
_decibelVolts = 20*Math.Log10(voltage/ElectricPotential.FromVolts(1));
54+
_decibelVolts = 20*Math.Log10(voltage.Volts/1);
9855
}
9956

10057
/// <summary>

UnitsNet/CustomCode/UnitClasses/Angle.extra.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22+
// Operator overloads not supported in Universal Windows Platform (WinRT Components)
23+
#if !WINDOWS_UWP
2224
using System;
2325

2426
namespace UnitsNet
@@ -35,4 +37,5 @@ public partial struct Angle
3537
return RotationalSpeed.FromRadiansPerSecond(angle.Radians/duration.Seconds);
3638
}
3739
}
38-
}
40+
}
41+
#endif

UnitsNet/CustomCode/UnitClasses/Area.extra.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22+
// Operator overloads not supported in Universal Windows Platform (WinRT Components)
23+
#if !WINDOWS_UWP
2224
namespace UnitsNet
2325
{
2426
public partial struct Area
@@ -28,4 +30,5 @@ public partial struct Area
2830
return Length.FromMeters(area.SquareMeters/length.Meters);
2931
}
3032
}
31-
}
33+
}
34+
#endif

UnitsNet/CustomCode/UnitClasses/BrakeSpecificFuelConsumption.extra.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22+
// Operator overloads not supported in Universal Windows Platform (WinRT Components)
23+
#if !WINDOWS_UWP
2224
namespace UnitsNet
2325
{
2426
public partial struct BrakeSpecificFuelConsumption
@@ -38,4 +40,5 @@ public partial struct BrakeSpecificFuelConsumption
3840
return specificEnergy.JoulesPerKilogram * bsfc.KilogramsPerJoule;
3941
}
4042
}
41-
}
43+
}
44+
#endif

0 commit comments

Comments
 (0)