DecimalByteSize.cs 2.2 KB

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