forked from angularsen/UnitsNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInformation.g.cs
More file actions
484 lines (408 loc) · 24.7 KB
/
Information.g.cs
File metadata and controls
484 lines (408 loc) · 24.7 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
//------------------------------------------------------------------------------
// <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>
/// In computing and telecommunications, a unit of information is the capacity of some standard data storage system or communication channel, used to measure the capacities of other systems and channels. In information theory, units of information are also used to measure the information contents or entropy of random variables.
/// </summary>
public struct Information
{
/// <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 InformationUnit _unit;
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
public double Value => _value;
/// <inheritdoc />
public InformationUnit 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>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public Information(double value, InformationUnit unit)
{
_value = value;
_unit = unit;
}
/// <summary>
/// The base unit of Information, which is Second. All conversions go via this value.
/// </summary>
public static InformationUnit BaseUnit { get; } = InformationUnit.Bit;
/// <summary>
/// Represents the largest possible value of Information.
/// </summary>
public static Information MaxValue { get; } = new Information(double.MaxValue, BaseUnit);
/// <summary>
/// Represents the smallest possible value of Information.
/// </summary>
public static Information MinValue { get; } = new Information(double.MinValue, BaseUnit);
/// <summary>
/// Gets an instance of this quantity with a value of 0 in the base unit Second.
/// </summary>
public static Information Zero { get; } = new Information(0, BaseUnit);
#region Conversion Properties
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Bit"/>
/// </summary>
public double Bits => As(InformationUnit.Bit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Byte"/>
/// </summary>
public double Bytes => As(InformationUnit.Byte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Exabit"/>
/// </summary>
public double Exabits => As(InformationUnit.Exabit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Exabyte"/>
/// </summary>
public double Exabytes => As(InformationUnit.Exabyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Exbibit"/>
/// </summary>
public double Exbibits => As(InformationUnit.Exbibit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Exbibyte"/>
/// </summary>
public double Exbibytes => As(InformationUnit.Exbibyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Gibibit"/>
/// </summary>
public double Gibibits => As(InformationUnit.Gibibit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Gibibyte"/>
/// </summary>
public double Gibibytes => As(InformationUnit.Gibibyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Gigabit"/>
/// </summary>
public double Gigabits => As(InformationUnit.Gigabit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Gigabyte"/>
/// </summary>
public double Gigabytes => As(InformationUnit.Gigabyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Kibibit"/>
/// </summary>
public double Kibibits => As(InformationUnit.Kibibit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Kibibyte"/>
/// </summary>
public double Kibibytes => As(InformationUnit.Kibibyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Kilobit"/>
/// </summary>
public double Kilobits => As(InformationUnit.Kilobit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Kilobyte"/>
/// </summary>
public double Kilobytes => As(InformationUnit.Kilobyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Mebibit"/>
/// </summary>
public double Mebibits => As(InformationUnit.Mebibit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Mebibyte"/>
/// </summary>
public double Mebibytes => As(InformationUnit.Mebibyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Megabit"/>
/// </summary>
public double Megabits => As(InformationUnit.Megabit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Megabyte"/>
/// </summary>
public double Megabytes => As(InformationUnit.Megabyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Pebibit"/>
/// </summary>
public double Pebibits => As(InformationUnit.Pebibit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Pebibyte"/>
/// </summary>
public double Pebibytes => As(InformationUnit.Pebibyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Petabit"/>
/// </summary>
public double Petabits => As(InformationUnit.Petabit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Petabyte"/>
/// </summary>
public double Petabytes => As(InformationUnit.Petabyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Tebibit"/>
/// </summary>
public double Tebibits => As(InformationUnit.Tebibit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Tebibyte"/>
/// </summary>
public double Tebibytes => As(InformationUnit.Tebibyte);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Terabit"/>
/// </summary>
public double Terabits => As(InformationUnit.Terabit);
/// <summary>
/// Gets a <see cref="double"/> value of this quantity converted into <see cref="InformationUnit.Terabyte"/>
/// </summary>
public double Terabytes => As(InformationUnit.Terabyte);
#endregion
#region Static Factory Methods
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Bit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromBits(double bits) => new Information(bits, InformationUnit.Bit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Byte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromBytes(double bytes) => new Information(bytes, InformationUnit.Byte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Exabit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromExabits(double exabits) => new Information(exabits, InformationUnit.Exabit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Exabyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromExabytes(double exabytes) => new Information(exabytes, InformationUnit.Exabyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Exbibit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromExbibits(double exbibits) => new Information(exbibits, InformationUnit.Exbibit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Exbibyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromExbibytes(double exbibytes) => new Information(exbibytes, InformationUnit.Exbibyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Gibibit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromGibibits(double gibibits) => new Information(gibibits, InformationUnit.Gibibit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Gibibyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromGibibytes(double gibibytes) => new Information(gibibytes, InformationUnit.Gibibyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Gigabit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromGigabits(double gigabits) => new Information(gigabits, InformationUnit.Gigabit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Gigabyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromGigabytes(double gigabytes) => new Information(gigabytes, InformationUnit.Gigabyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Kibibit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromKibibits(double kibibits) => new Information(kibibits, InformationUnit.Kibibit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Kibibyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromKibibytes(double kibibytes) => new Information(kibibytes, InformationUnit.Kibibyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Kilobit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromKilobits(double kilobits) => new Information(kilobits, InformationUnit.Kilobit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Kilobyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromKilobytes(double kilobytes) => new Information(kilobytes, InformationUnit.Kilobyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Mebibit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromMebibits(double mebibits) => new Information(mebibits, InformationUnit.Mebibit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Mebibyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromMebibytes(double mebibytes) => new Information(mebibytes, InformationUnit.Mebibyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Megabit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromMegabits(double megabits) => new Information(megabits, InformationUnit.Megabit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Megabyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromMegabytes(double megabytes) => new Information(megabytes, InformationUnit.Megabyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Pebibit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromPebibits(double pebibits) => new Information(pebibits, InformationUnit.Pebibit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Pebibyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromPebibytes(double pebibytes) => new Information(pebibytes, InformationUnit.Pebibyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Petabit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromPetabits(double petabits) => new Information(petabits, InformationUnit.Petabit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Petabyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromPetabytes(double petabytes) => new Information(petabytes, InformationUnit.Petabyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Tebibit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromTebibits(double tebibits) => new Information(tebibits, InformationUnit.Tebibit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Tebibyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromTebibytes(double tebibytes) => new Information(tebibytes, InformationUnit.Tebibyte);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Terabit"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromTerabits(double terabits) => new Information(terabits, InformationUnit.Terabit);
/// <summary>
/// Creates a <see cref="Information"/> from <see cref="InformationUnit.Terabyte"/>.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
public static Information FromTerabytes(double terabytes) => new Information(terabytes, InformationUnit.Terabyte);
/// <summary>
/// Dynamically convert from value and unit enum <see cref="InformationUnit" /> to <see cref="Information" />.
/// </summary>
/// <param name="value">Value to convert from.</param>
/// <param name="fromUnit">Unit to convert from.</param>
/// <returns>Information unit value.</returns>
public static Information From(double value, InformationUnit fromUnit)
{
return new Information(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(InformationUnit unit) => GetValueAs(unit);
/// <summary>
/// Converts this Information to another Information with the unit representation <paramref name="unit" />.
/// </summary>
/// <returns>A Information with the specified unit.</returns>
public Information ToUnit(InformationUnit unit)
{
var convertedValue = GetValueAs(unit);
return new Information(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
{
InformationUnit.Bit => _value,
InformationUnit.Byte => _value * 8,
InformationUnit.Exabit => (_value) * 1e18d,
InformationUnit.Exabyte => (_value * 8) * 1e18d,
InformationUnit.Exbibit => (_value) * (1024d * 1024 * 1024 * 1024 * 1024 * 1024),
InformationUnit.Exbibyte => (_value * 8) * (1024d * 1024 * 1024 * 1024 * 1024 * 1024),
InformationUnit.Gibibit => (_value) * (1024d * 1024 * 1024),
InformationUnit.Gibibyte => (_value * 8) * (1024d * 1024 * 1024),
InformationUnit.Gigabit => (_value) * 1e9d,
InformationUnit.Gigabyte => (_value * 8) * 1e9d,
InformationUnit.Kibibit => (_value) * 1024d,
InformationUnit.Kibibyte => (_value * 8) * 1024d,
InformationUnit.Kilobit => (_value) * 1e3d,
InformationUnit.Kilobyte => (_value * 8) * 1e3d,
InformationUnit.Mebibit => (_value) * (1024d * 1024),
InformationUnit.Mebibyte => (_value * 8) * (1024d * 1024),
InformationUnit.Megabit => (_value) * 1e6d,
InformationUnit.Megabyte => (_value * 8) * 1e6d,
InformationUnit.Pebibit => (_value) * (1024d * 1024 * 1024 * 1024 * 1024),
InformationUnit.Pebibyte => (_value * 8) * (1024d * 1024 * 1024 * 1024 * 1024),
InformationUnit.Petabit => (_value) * 1e15d,
InformationUnit.Petabyte => (_value * 8) * 1e15d,
InformationUnit.Tebibit => (_value) * (1024d * 1024 * 1024 * 1024),
InformationUnit.Tebibyte => (_value * 8) * (1024d * 1024 * 1024 * 1024),
InformationUnit.Terabit => (_value) * 1e12d,
InformationUnit.Terabyte => (_value * 8) * 1e12d,
_ => throw new NotImplementedException($"Can not convert {Unit} to base units.")
};
}
private double GetValueAs(InformationUnit unit)
{
if (Unit == unit)
return _value;
var baseUnitValue = GetValueInBaseUnit();
return unit switch
{
InformationUnit.Bit => baseUnitValue,
InformationUnit.Byte => baseUnitValue / 8,
InformationUnit.Exabit => (baseUnitValue) / 1e18d,
InformationUnit.Exabyte => (baseUnitValue / 8) / 1e18d,
InformationUnit.Exbibit => (baseUnitValue) / (1024d * 1024 * 1024 * 1024 * 1024 * 1024),
InformationUnit.Exbibyte => (baseUnitValue / 8) / (1024d * 1024 * 1024 * 1024 * 1024 * 1024),
InformationUnit.Gibibit => (baseUnitValue) / (1024d * 1024 * 1024),
InformationUnit.Gibibyte => (baseUnitValue / 8) / (1024d * 1024 * 1024),
InformationUnit.Gigabit => (baseUnitValue) / 1e9d,
InformationUnit.Gigabyte => (baseUnitValue / 8) / 1e9d,
InformationUnit.Kibibit => (baseUnitValue) / 1024d,
InformationUnit.Kibibyte => (baseUnitValue / 8) / 1024d,
InformationUnit.Kilobit => (baseUnitValue) / 1e3d,
InformationUnit.Kilobyte => (baseUnitValue / 8) / 1e3d,
InformationUnit.Mebibit => (baseUnitValue) / (1024d * 1024),
InformationUnit.Mebibyte => (baseUnitValue / 8) / (1024d * 1024),
InformationUnit.Megabit => (baseUnitValue) / 1e6d,
InformationUnit.Megabyte => (baseUnitValue / 8) / 1e6d,
InformationUnit.Pebibit => (baseUnitValue) / (1024d * 1024 * 1024 * 1024 * 1024),
InformationUnit.Pebibyte => (baseUnitValue / 8) / (1024d * 1024 * 1024 * 1024 * 1024),
InformationUnit.Petabit => (baseUnitValue) / 1e15d,
InformationUnit.Petabyte => (baseUnitValue / 8) / 1e15d,
InformationUnit.Tebibit => (baseUnitValue) / (1024d * 1024 * 1024 * 1024),
InformationUnit.Tebibyte => (baseUnitValue / 8) / (1024d * 1024 * 1024 * 1024),
InformationUnit.Terabit => (baseUnitValue) / 1e12d,
InformationUnit.Terabyte => (baseUnitValue / 8) / 1e12d,
_ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.")
};
}
#endregion
}
}