DecimalByteSize.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. namespace Optimizer {
  2. public partial struct ByteSize {
  3. public const long BytesInKiloByte = 1_000;
  4. public const long BytesInMegaByte = 1_000_000;
  5. public const long BytesInGigaByte = 1_000_000_000;
  6. public const long BytesInTeraByte = 1_000_000_000_000;
  7. public const long BytesInPetaByte = 1_000_000_000_000_000;
  8. public const string KiloByteSymbol = "KB";
  9. public const string MegaByteSymbol = "MB";
  10. public const string GigaByteSymbol = "GB";
  11. public const string TeraByteSymbol = "TB";
  12. public const string PetaByteSymbol = "PB";
  13. public double KiloBytes => Bytes / BytesInKiloByte;
  14. public double MegaBytes => Bytes / BytesInMegaByte;
  15. public double GigaBytes => Bytes / BytesInGigaByte;
  16. public double TeraBytes => Bytes / BytesInTeraByte;
  17. public double PetaBytes => Bytes / BytesInPetaByte;
  18. public static ByteSize FromKiloBytes(double value) {
  19. return new ByteSize(value * BytesInKiloByte);
  20. }
  21. public static ByteSize FromMegaBytes(double value) {
  22. return new ByteSize(value * BytesInMegaByte);
  23. }
  24. public static ByteSize FromGigaBytes(double value) {
  25. return new ByteSize(value * BytesInGigaByte);
  26. }
  27. public static ByteSize FromTeraBytes(double value) {
  28. return new ByteSize(value * BytesInTeraByte);
  29. }
  30. public static ByteSize FromPetaBytes(double value) {
  31. return new ByteSize(value * BytesInPetaByte);
  32. }
  33. public ByteSize AddKiloBytes(double value) {
  34. return this + ByteSize.FromKiloBytes(value);
  35. }
  36. public ByteSize AddMegaBytes(double value) {
  37. return this + ByteSize.FromMegaBytes(value);
  38. }
  39. public ByteSize AddGigaBytes(double value) {
  40. return this + ByteSize.FromGigaBytes(value);
  41. }
  42. public ByteSize AddTeraBytes(double value) {
  43. return this + ByteSize.FromTeraBytes(value);
  44. }
  45. public ByteSize AddPetaBytes(double value) {
  46. return this + ByteSize.FromPetaBytes(value);
  47. }
  48. }
  49. }