-
Notifications
You must be signed in to change notification settings - Fork 412
Expand file tree
/
Copy pathAreaPerLength.g.cs
More file actions
217 lines (181 loc) · 10.2 KB
/
Copy pathAreaPerLength.g.cs
File metadata and controls
217 lines (181 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by \generate-code.bat.
//
// Changes to this file will be lost when the code is regenerated.
// The build server regenerates the code before each build and a pre-build
// step will regenerate the code on each local build.
//
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
//
// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities.
//
// </auto-generated>
//------------------------------------------------------------------------------
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet.
using System;
using UnitsNet.Units;
namespace UnitsNet
{
/// <inheritdoc />
/// <summary>
/// The magnitude of area per unit length, typically used in structural engineering to specify distributed reinforcement.
/// </summary>
public struct AreaPerLength
{
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
private readonly double _value;
/// <summary>
/// The unit this quantity was constructed with.
/// </summary>
private readonly AreaPerLengthUnit _unit;
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
public double Value => _value;
/// <inheritdoc />
public AreaPerLengthUnit Unit => _unit;
/// <summary>
/// Creates the quantity with the given numeric value and unit.
/// </summary>
/// <param name="value">The numeric value to construct this quantity with.</param>
/// <param name="unit">The unit representation to construct this quantity with.</param>
public AreaPerLength(double value, AreaPerLengthUnit unit)
{
_value = value;
_unit = unit;
}
/// <summary>
/// The base unit of AreaPerLength, which is Second. All conversions go via this value.
/// </summary>
public static AreaPerLengthUnit BaseUnit { get; } = AreaPerLengthUnit.SquareMeterPerMeter;
/// <summary>
/// Represents the largest possible value of AreaPerLength.
/// </summary>
public static AreaPerLength MaxValue { get; } = new AreaPerLength(double.MaxValue, BaseUnit);
/// <summary>
/// Represents the smallest possible value of AreaPerLength.
/// </summary>
public static AreaPerLength MinValue { get; } = new AreaPerLength(double.MinValue, BaseUnit);
/// <summary>
/// Gets an instance of this quantity with a value of 0 in the base unit Second.
/// </summary>
public static AreaPerLength Zero { get; } = new AreaPerLength(0, BaseUnit);
#region Conversion Properties
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaPerLengthUnit.SquareCentimeterPerMeter"/>
/// </summary>
public double SquareCentimetersPerMeter => As(AreaPerLengthUnit.SquareCentimeterPerMeter);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaPerLengthUnit.SquareFootPerFoot"/>
/// </summary>
public double SquareFeetPerFoot => As(AreaPerLengthUnit.SquareFootPerFoot);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaPerLengthUnit.SquareInchPerFoot"/>
/// </summary>
public double SquareInchesPerFoot => As(AreaPerLengthUnit.SquareInchPerFoot);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaPerLengthUnit.SquareInchPerInch"/>
/// </summary>
public double SquareInchesPerInch => As(AreaPerLengthUnit.SquareInchPerInch);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaPerLengthUnit.SquareMeterPerMeter"/>
/// </summary>
public double SquareMetersPerMeter => As(AreaPerLengthUnit.SquareMeterPerMeter);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="AreaPerLengthUnit.SquareMillimeterPerMeter"/>
/// </summary>
public double SquareMillimetersPerMeter => As(AreaPerLengthUnit.SquareMillimeterPerMeter);
#endregion
#region Static Factory Methods
/// <summary>
/// Creates a <see cref="AreaPerLength"/> from <see cref="AreaPerLengthUnit.SquareCentimeterPerMeter"/>.
/// </summary>
public static AreaPerLength FromSquareCentimetersPerMeter(double squarecentimeterspermeter) => new AreaPerLength(squarecentimeterspermeter, AreaPerLengthUnit.SquareCentimeterPerMeter);
/// <summary>
/// Creates a <see cref="AreaPerLength"/> from <see cref="AreaPerLengthUnit.SquareFootPerFoot"/>.
/// </summary>
public static AreaPerLength FromSquareFeetPerFoot(double squarefeetperfoot) => new AreaPerLength(squarefeetperfoot, AreaPerLengthUnit.SquareFootPerFoot);
/// <summary>
/// Creates a <see cref="AreaPerLength"/> from <see cref="AreaPerLengthUnit.SquareInchPerFoot"/>.
/// </summary>
public static AreaPerLength FromSquareInchesPerFoot(double squareinchesperfoot) => new AreaPerLength(squareinchesperfoot, AreaPerLengthUnit.SquareInchPerFoot);
/// <summary>
/// Creates a <see cref="AreaPerLength"/> from <see cref="AreaPerLengthUnit.SquareInchPerInch"/>.
/// </summary>
public static AreaPerLength FromSquareInchesPerInch(double squareinchesperinch) => new AreaPerLength(squareinchesperinch, AreaPerLengthUnit.SquareInchPerInch);
/// <summary>
/// Creates a <see cref="AreaPerLength"/> from <see cref="AreaPerLengthUnit.SquareMeterPerMeter"/>.
/// </summary>
public static AreaPerLength FromSquareMetersPerMeter(double squaremeterspermeter) => new AreaPerLength(squaremeterspermeter, AreaPerLengthUnit.SquareMeterPerMeter);
/// <summary>
/// Creates a <see cref="AreaPerLength"/> from <see cref="AreaPerLengthUnit.SquareMillimeterPerMeter"/>.
/// </summary>
public static AreaPerLength FromSquareMillimetersPerMeter(double squaremillimeterspermeter) => new AreaPerLength(squaremillimeterspermeter, AreaPerLengthUnit.SquareMillimeterPerMeter);
/// <summary>
/// Dynamically convert from value and unit enum <see cref="AreaPerLengthUnit" /> to <see cref="AreaPerLength" />.
/// </summary>
/// <param name="value">Value to convert from.</param>
/// <param name="fromUnit">Unit to convert from.</param>
/// <returns>AreaPerLength unit value.</returns>
public static AreaPerLength From(double value, AreaPerLengthUnit fromUnit)
{
return new AreaPerLength(value, fromUnit);
}
#endregion
#region Conversion Methods
/// <summary>
/// Convert to the unit representation <paramref name="unit" />.
/// </summary>
/// <returns>Value converted to the specified unit.</returns>
public double As(AreaPerLengthUnit unit) => GetValueAs(unit);
/// <summary>
/// Converts this AreaPerLength to another AreaPerLength with the unit representation <paramref name="unit" />.
/// </summary>
/// <returns>A AreaPerLength with the specified unit.</returns>
public AreaPerLength ToUnit(AreaPerLengthUnit unit)
{
var convertedValue = GetValueAs(unit);
return new AreaPerLength(convertedValue, unit);
}
/// <summary>
/// Converts the current value + unit to the base unit.
/// This is typically the first step in converting from one unit to another.
/// </summary>
/// <returns>The value in the base unit representation.</returns>
private double GetValueInBaseUnit()
{
return Unit switch
{
AreaPerLengthUnit.SquareCentimeterPerMeter => _value * 1e-4,
AreaPerLengthUnit.SquareFootPerFoot => _value * 0.09290304 / 0.3048,
AreaPerLengthUnit.SquareInchPerFoot => _value * 0.00064516 / 0.3048,
AreaPerLengthUnit.SquareInchPerInch => _value * 0.00064516 / 0.0254,
AreaPerLengthUnit.SquareMeterPerMeter => _value,
AreaPerLengthUnit.SquareMillimeterPerMeter => _value * 1e-6,
_ => throw new NotImplementedException($"Can't convert {Unit} to base units.")
};
}
private double GetValueAs(AreaPerLengthUnit unit)
{
if (Unit == unit)
return _value;
var baseUnitValue = GetValueInBaseUnit();
return unit switch
{
AreaPerLengthUnit.SquareCentimeterPerMeter => baseUnitValue / 1e-4,
AreaPerLengthUnit.SquareFootPerFoot => baseUnitValue * 0.3048 / 0.09290304,
AreaPerLengthUnit.SquareInchPerFoot => baseUnitValue * 0.3048 / 0.00064516,
AreaPerLengthUnit.SquareInchPerInch => baseUnitValue * 0.0254 / 0.00064516,
AreaPerLengthUnit.SquareMeterPerMeter => baseUnitValue,
AreaPerLengthUnit.SquareMillimeterPerMeter => baseUnitValue / 1e-6,
_ => throw new NotImplementedException($"Can't convert {Unit} to {unit}.")
};
}
#endregion
}
}