Skip to content

Commit 823ed2a

Browse files
committed
Temperature: Add custom arithmetic
Use TemperatureDelta for + and - operators.
1 parent a3e6216 commit 823ed2a

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright © 2007 Andreas Gullberg Larsen ([email protected]).
2+
// https://github.com/anjdreas/UnitsNet
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
#if !WINDOWS_UWP
23+
// Operator overloads not supported in Universal Windows Platform (WinRT Components)
24+
using System;
25+
26+
namespace UnitsNet
27+
{
28+
public partial struct Temperature
29+
{
30+
public static Temperature operator +(Temperature left, TemperatureDelta right)
31+
{
32+
return new Temperature(left.Kelvins + right.KelvinsDelta);
33+
}
34+
35+
public static Temperature operator +(TemperatureDelta left, Temperature right)
36+
{
37+
return new Temperature(left.KelvinsDelta + right.Kelvins);
38+
}
39+
40+
public static Temperature operator -(Temperature left, TemperatureDelta right)
41+
{
42+
return new Temperature(left.Kelvins - right.KelvinsDelta);
43+
}
44+
45+
public static TemperatureDelta operator -(Temperature left, Temperature right)
46+
{
47+
return new TemperatureDelta(left.Kelvins - right.Kelvins);
48+
}
49+
50+
// public static Temperature operator *(double left, Temperature right)
51+
// {
52+
// return new Temperature(left * right.Kelvins);
53+
// }
54+
//
55+
// public static Temperature operator *(Temperature left, double right)
56+
// {
57+
// return new Temperature(left.Kelvins * right);
58+
// }
59+
//
60+
// public static Temperature operator /(Temperature left, double right)
61+
// {
62+
// return new Temperature(left.Kelvins / right);
63+
// }
64+
//
65+
// public static double operator /(Temperature left, Temperature right)
66+
// {
67+
// return Convert.ToDouble(left.Kelvins / right.Kelvins);
68+
// }
69+
}
70+
}
71+
72+
#endif

0 commit comments

Comments
 (0)