Skip to content

Commit a67529e

Browse files
committed
Duplicate source code into WRC - compiles OK
1 parent 38a502c commit a67529e

File tree

165 files changed

+15665
-13
lines changed

Some content is hidden

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

165 files changed

+15665
-13
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
2+
// https://github.com/angularsen/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+
using System;
23+
using UnitsNet.Units;
24+
25+
namespace UnitsNet
26+
{
27+
/// <summary>
28+
/// Unable to parse because more than one unit of the given quantity type had this exact unit abbreviation.
29+
/// Example: Length.Parse("1 pt") will throw <see cref="AmbiguousUnitParseException" />, because both
30+
/// <see cref="LengthUnit.DtpPoint" /> and
31+
/// <see cref="LengthUnit.PrinterPoint" /> have "pt" as their abbreviation.
32+
/// </summary>
33+
#if WINDOWS_UWP
34+
internal
35+
#else
36+
public
37+
#endif
38+
class AmbiguousUnitParseException : UnitsNetException
39+
{
40+
/// <inheritdoc />
41+
public AmbiguousUnitParseException(string message) : base(message)
42+
{
43+
HResult = 2;
44+
}
45+
46+
/// <inheritdoc />
47+
public AmbiguousUnitParseException(string message, Exception innerException) : base(message, innerException)
48+
{
49+
HResult = 2;
50+
}
51+
}
52+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
2+
// https://github.com/angularsen/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+
using System;
23+
[assembly: CLSCompliant(true)]
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
// Copyright (c) 2013 Andreas Gullberg Larsen ([email protected]).
2+
// https://github.com/angularsen/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+
using System;
23+
using System.Text;
24+
using System.Linq;
25+
26+
namespace UnitsNet
27+
{
28+
/// <summary>
29+
/// Represents the base dimensions of a quantity.
30+
/// </summary>
31+
public sealed class BaseDimensions
32+
{
33+
/// <inheritdoc />
34+
public BaseDimensions(int length, int mass, int time, int current, int temperature, int amount, int luminousIntensity)
35+
{
36+
Length = length;
37+
Mass = mass;
38+
Time = time;
39+
Current = current;
40+
Temperature = temperature;
41+
Amount = amount;
42+
LuminousIntensity = luminousIntensity;
43+
}
44+
45+
/// <summary>
46+
/// Checks if the dimensions represent a base quantity.
47+
/// </summary>
48+
/// <returns>True if the dimensions represent a base quantity, otherwise false.</returns>
49+
public bool IsBaseQuantity()
50+
{
51+
var dimensionsArray = new int[]{Length, Mass, Time, Current, Temperature, Amount, LuminousIntensity};
52+
bool onlyOneEqualsOne = dimensionsArray.Where(dimension => dimension == 1).Take(2).Count() == 1;
53+
return onlyOneEqualsOne;
54+
}
55+
56+
/// <summary>
57+
/// Checks if the dimensions represent a derived quantity.
58+
/// </summary>
59+
/// <returns>True if the dimensions represent a derived quantity, otherwise false.</returns>
60+
public bool IsDerivedQuantity()
61+
{
62+
return !IsBaseQuantity() && !IsDimensionless();
63+
}
64+
65+
/// <summary>
66+
/// Checks if this base dimensions object represents a dimensionless quantity.
67+
/// </summary>
68+
/// <returns>True if this object represents a dimensionless quantity, otherwise false.</returns>
69+
public bool IsDimensionless()
70+
{
71+
return this == Dimensionless;
72+
}
73+
74+
/// <inheritdoc />
75+
public override bool Equals(object obj)
76+
{
77+
if(obj is null || !(obj is BaseDimensions))
78+
return false;
79+
80+
var other = (BaseDimensions)obj;
81+
82+
return Length == other.Length &&
83+
Mass == other.Mass &&
84+
Time == other.Time &&
85+
Current == other.Current &&
86+
Temperature == other.Temperature &&
87+
Amount == other.Amount &&
88+
LuminousIntensity == other.LuminousIntensity;
89+
}
90+
91+
/// <inheritdoc />
92+
public override int GetHashCode()
93+
{
94+
return new {Length, Mass, Time, Current, Temperature, Amount, LuminousIntensity}.GetHashCode();
95+
}
96+
97+
/// <summary>
98+
/// Get resulting dimensions after multiplying two dimensions, by performing addition of each dimension.
99+
/// </summary>
100+
/// <param name="right">Other dimensions.</param>
101+
/// <returns>Resulting dimensions.</returns>
102+
public BaseDimensions Multiply(BaseDimensions right)
103+
{
104+
if(right is null)
105+
throw new ArgumentNullException(nameof(right));
106+
107+
return new BaseDimensions(
108+
Length + right.Length,
109+
Mass + right.Mass,
110+
Time + right.Time,
111+
Current + right.Current,
112+
Temperature + right.Temperature,
113+
Amount + right.Amount,
114+
LuminousIntensity + right.LuminousIntensity);
115+
}
116+
117+
/// <summary>
118+
/// Get resulting dimensions after dividing two dimensions, by performing subtraction of each dimension.
119+
/// </summary>
120+
/// <param name="right">Other dimensions.</param>
121+
/// <returns>Resulting dimensions.</returns>
122+
public BaseDimensions Divide(BaseDimensions right)
123+
{
124+
if(right is null)
125+
throw new ArgumentNullException(nameof(right));
126+
127+
return new BaseDimensions(
128+
Length - right.Length,
129+
Mass - right.Mass,
130+
Time - right.Time,
131+
Current - right.Current,
132+
Temperature - right.Temperature,
133+
Amount - right.Amount,
134+
LuminousIntensity - right.LuminousIntensity);
135+
}
136+
137+
#if !WINDOWS_UWP
138+
139+
/// <summary>
140+
/// Check if two dimensions are equal.
141+
/// </summary>
142+
/// <param name="left">Left.</param>
143+
/// <param name="right">Right.</param>
144+
/// <returns>True if equal.</returns>
145+
public static bool operator ==(BaseDimensions left, BaseDimensions right)
146+
{
147+
return left is null ? right is null : left.Equals(right);
148+
}
149+
150+
/// <summary>
151+
/// Check if two dimensions are unequal.
152+
/// </summary>
153+
/// <param name="left">Left.</param>
154+
/// <param name="right">Right.</param>
155+
/// <returns>True if not equal.</returns>
156+
public static bool operator !=(BaseDimensions left, BaseDimensions right)
157+
{
158+
return !(left == right);
159+
}
160+
161+
/// <summary>
162+
/// Multiply two dimensions.
163+
/// </summary>
164+
/// <param name="left">Left.</param>
165+
/// <param name="right">Right.</param>
166+
/// <returns>Resulting dimensions.</returns>
167+
public static BaseDimensions operator *(BaseDimensions left, BaseDimensions right)
168+
{
169+
if(left is null)
170+
throw new ArgumentNullException(nameof(left));
171+
else if(right is null)
172+
throw new ArgumentNullException(nameof(right));
173+
174+
return left.Multiply(right);
175+
}
176+
177+
/// <summary>
178+
/// Divide two dimensions.
179+
/// </summary>
180+
/// <param name="left">Left.</param>
181+
/// <param name="right">Right.</param>
182+
/// <returns>Resulting dimensions.</returns>
183+
public static BaseDimensions operator /(BaseDimensions left, BaseDimensions right)
184+
{
185+
if(left is null)
186+
throw new ArgumentNullException(nameof(left));
187+
else if(right is null)
188+
throw new ArgumentNullException(nameof(right));
189+
190+
return left.Divide(right);
191+
}
192+
193+
#endif
194+
195+
/// <inheritdoc />
196+
public override string ToString()
197+
{
198+
var sb = new StringBuilder();
199+
200+
AppendDimensionString(sb, "Length", Length);
201+
AppendDimensionString(sb, "Mass", Mass);
202+
AppendDimensionString(sb, "Time", Time);
203+
AppendDimensionString(sb, "Current", Current);
204+
AppendDimensionString(sb, "Temperature", Temperature);
205+
AppendDimensionString(sb, "Amount", Amount);
206+
AppendDimensionString(sb, "LuminousIntensity", LuminousIntensity);
207+
208+
return sb.ToString();
209+
}
210+
211+
private static void AppendDimensionString(StringBuilder sb, string name, int value)
212+
{
213+
var absoluteValue = Math.Abs(value);
214+
215+
if(absoluteValue > 0)
216+
{
217+
sb.AppendFormat("[{0}]", name);
218+
219+
if(absoluteValue > 1)
220+
sb.AppendFormat("^{0}", value);
221+
}
222+
}
223+
224+
/// <summary>
225+
/// Gets the length dimensions (L).
226+
/// </summary>
227+
public int Length { get; }
228+
229+
/// <summary>
230+
/// Gets the mass dimensions (M).
231+
/// </summary>
232+
public int Mass{ get; }
233+
234+
/// <summary>
235+
/// Gets the time dimensions (T).
236+
/// </summary>
237+
public int Time{ get; }
238+
239+
/// <summary>
240+
/// Gets the electric current dimensions (I).
241+
/// </summary>
242+
public int Current{ get; }
243+
244+
/// <summary>
245+
/// Gets the temperature dimensions (Θ).
246+
/// </summary>
247+
public int Temperature{ get; }
248+
249+
/// <summary>
250+
/// Gets the amount of substance dimensions (N).
251+
/// </summary>
252+
public int Amount{ get; }
253+
254+
/// <summary>
255+
/// Gets the luminous intensity dimensions (J).
256+
/// </summary>
257+
public int LuminousIntensity{ get; }
258+
259+
/// <summary>
260+
/// Represents a dimensionless (unitless) quantity.
261+
/// </summary>
262+
public static BaseDimensions Dimensionless { get; } = new BaseDimensions(0, 0, 0, 0, 0, 0, 0);
263+
}
264+
}

0 commit comments

Comments
 (0)