-
Notifications
You must be signed in to change notification settings - Fork 50
/
DecimalByteSize.cs
76 lines (63 loc) · 2.25 KB
/
DecimalByteSize.cs
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
using System;
using System.Globalization;
namespace ByteSizeLib
{
public partial struct ByteSize
{
public const long BytesInKiloByte = 1_000;
public const long BytesInMegaByte = 1_000_000;
public const long BytesInGigaByte = 1_000_000_000;
public const long BytesInTeraByte = 1_000_000_000_000;
public const long BytesInPetaByte = 1_000_000_000_000_000;
public const string KiloByteSymbol = "KB";
public const string MegaByteSymbol = "MB";
public const string GigaByteSymbol = "GB";
public const string TeraByteSymbol = "TB";
public const string PetaByteSymbol = "PB";
public double KiloBytes => Bytes / BytesInKiloByte;
public double MegaBytes => Bytes / BytesInMegaByte;
public double GigaBytes => Bytes / BytesInGigaByte;
public double TeraBytes => Bytes / BytesInTeraByte;
public double PetaBytes => Bytes / BytesInPetaByte;
public static ByteSize FromKiloBytes(double value)
{
return new ByteSize(value * BytesInKiloByte);
}
public static ByteSize FromMegaBytes(double value)
{
return new ByteSize(value * BytesInMegaByte);
}
public static ByteSize FromGigaBytes(double value)
{
return new ByteSize(value * BytesInGigaByte);
}
public static ByteSize FromTeraBytes(double value)
{
return new ByteSize(value * BytesInTeraByte);
}
public static ByteSize FromPetaBytes(double value)
{
return new ByteSize(value * BytesInPetaByte);
}
public ByteSize AddKiloBytes(double value)
{
return this + ByteSize.FromKiloBytes(value);
}
public ByteSize AddMegaBytes(double value)
{
return this + ByteSize.FromMegaBytes(value);
}
public ByteSize AddGigaBytes(double value)
{
return this + ByteSize.FromGigaBytes(value);
}
public ByteSize AddTeraBytes(double value)
{
return this + ByteSize.FromTeraBytes(value);
}
public ByteSize AddPetaBytes(double value)
{
return this + ByteSize.FromPetaBytes(value);
}
}
}