Prose.ByteSize

References
Provides utility methods for converting and formatting bits and bytes. Code copied from: https://github.com/omar/ByteSize

Constructors

ByteSize

#
public ByteSize(double byteSize)
Create a new bytesize.
byteSize (double)Number of bytes.

Fields

BitsInByte

#
public const long BitsInByte = 8
The number of bits in a byte.

BitSymbol

#
public const string BitSymbol = "b"
Bit unit symbol.

BytesInGigaByte

#
public const long BytesInGigaByte = 1073741824
The number of bytes in a gigabyte.

BytesInKiloByte

#
public const long BytesInKiloByte = 1024
The number of bytes in a kilobyte.

BytesInMegaByte

#
public const long BytesInMegaByte = 1048576
The number of bytes in a megabyte.

BytesInPetaByte

#
public const long BytesInPetaByte = 1125899906842624
The number of bytes in a petabyte.

BytesInTeraByte

#
public const long BytesInTeraByte = 1099511627776
The number of bytes in a terabyte.

ByteSymbol

#
public const string ByteSymbol = "B"
Byte unit symbol.

GigaByteSymbol

#
public const string GigaByteSymbol = "GB"
Gigabyte unit symbol.

KiloByteSymbol

#
public const string KiloByteSymbol = "KB"
Kilobyte unit symbol.

MaxValue

#
public static readonly Prose.ByteSize MaxValue
Largest representable size.

MegaByteSymbol

#
public const string MegaByteSymbol = "MB"
Megabyte unit symbol.

MinValue

#
public static readonly Prose.ByteSize MinValue
Smallest representable size.

PetaByteSymbol

#
public const string PetaByteSymbol = "PB"
Petabyte unit symbol.

TeraByteSymbol

#
public const string TeraByteSymbol = "TB"
Terabyte unit symbol.

Properties

Bits

#
public long Bits { get; }
Gets the total number of bits in this size.

Bytes

#
public double Bytes { get; }
Gets the total number of bytes in this size.

GigaBytes

#
public double GigaBytes { get; }
Gets the total number of gigabytes in this size.

KiloBytes

#
public double KiloBytes { get; }
Gets the total number of kilobytes in this size.

LargestWholeNumberSymbol

#
public string LargestWholeNumberSymbol { get; }
Gets the unit symbol which represents the largest non-zero amount.

LargestWholeNumberValue

#
public double LargestWholeNumberValue { get; }
Gets the amount of the largest non-zero unit.

MegaBytes

#
public double MegaBytes { get; }
Gets the total number of megabytes in this size.

PetaBytes

#
public double PetaBytes { get; }
Gets the total number of petabytes in this size.

TeraBytes

#
public double TeraBytes { get; }
Gets the total number of terabytes in this size.

Methods

Add

#
public Prose.ByteSize Add(ByteSize bs)
Add to this size.
bs (Prose.ByteSize)

AddBits

#
public Prose.ByteSize AddBits(long value)
Add to this size.
value (long)

AddBytes

#
public Prose.ByteSize AddBytes(double value)
Add to this size.
value (double)

AddGigaBytes

#
public Prose.ByteSize AddGigaBytes(double value)
Add to this size.
value (double)

AddKiloBytes

#
public Prose.ByteSize AddKiloBytes(double value)
Add to this size.
value (double)

AddMegaBytes

#
public Prose.ByteSize AddMegaBytes(double value)
Add to this size.
value (double)

AddPetaBytes

#
public Prose.ByteSize AddPetaBytes(double value)
Add to this size.
value (double)

AddTeraBytes

#
public Prose.ByteSize AddTeraBytes(double value)
Add to this size.
value (double)

CompareTo

#
public int CompareTo(ByteSize other)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
other (Prose.ByteSize)An object to compare with this instance.

Equals

#
public bool Equals(ByteSize value)
Test for equality.
value (Prose.ByteSize)

Equals

#
public override bool Equals(object value)
Test for equality.
value (object)
ValueType.Equals

FromBits

#
public static Prose.ByteSize FromBits(long value)
Create a ByteSize instance from a number of bits.
value (long)

FromBytes

#
public static Prose.ByteSize FromBytes(double value)
Create a ByteSize instance from a number of bytes.
value (double)

FromGigaBytes

#
public static Prose.ByteSize FromGigaBytes(double value)
Create a ByteSize instance from a number of megabytes.
value (double)

FromKiloBytes

#
public static Prose.ByteSize FromKiloBytes(double value)
Create a ByteSize instance from a number of kilobytes.
value (double)

FromMegaBytes

#
public static Prose.ByteSize FromMegaBytes(double value)
Create a ByteSize instance from a number of megabytes.
value (double)

FromPetaBytes

#
public static Prose.ByteSize FromPetaBytes(double value)
Create a ByteSize instance from a number of petabytes.
value (double)

FromTeraBytes

#
public static Prose.ByteSize FromTeraBytes(double value)
Create a ByteSize instance from a number of terabytes.
value (double)

GetHashCode

#
public override int GetHashCode()
Returns the hash code for this instance.
A 32-bit signed integer that is the hash code for this instance.

Parse

#
public static Prose.ByteSize Parse(string s)
Parse a string representing a size.
s (string)

Subtract

#
public Prose.ByteSize Subtract(ByteSize bs)
Add to this size.
bs (Prose.ByteSize)

ToString

#
public override string ToString()
Converts the value of the current ByteSize object to a string. The metric prefix symbol (bit, byte, kilo, mega, giga, tera) used is the largest metric prefix such that the corresponding value is greater than or equal to one.

ToString

#
public string ToString(string format)
Format this instance using a formatting pattern.
format (string)

TryParse

#
public static bool TryParse(string s, out ByteSize result)
Try to parse a string representing a size.
s (string)String to parse.
result (out Prose.ByteSize)Result.
True on success.

Operators

OperationResultDescription
Prose.ByteSize+Prose.ByteSizeProse.ByteSizeAdd two sizes.
Prose.ByteSize==Prose.ByteSizeboolTest two sizes for equality.
Prose.ByteSize>Prose.ByteSizeboolTest two sizes for larger than ness.
Prose.ByteSize>=Prose.ByteSizeboolTest two sizes for larger than ness.
Prose.ByteSize!=Prose.ByteSizeboolTest two sizes for inequality.
Prose.ByteSize<Prose.ByteSizeboolTest two sizes for smaller than ness.
Prose.ByteSize<=Prose.ByteSizeboolTest two sizes for smaller than ness.
Prose.ByteSize-Prose.ByteSizeProse.ByteSizeSubtract two sizes.
-Prose.ByteSizeProse.ByteSizeNegate a size.