Exemplo n.º 1
0
 public static long ToBytes(this long size, FileSizeHelper.Units inputUnit) {
     switch (inputUnit) {
     case FileSizeHelper.Units.B:
         return size;
     case FileSizeHelper.Units.kB:
         return size*1024;
     case FileSizeHelper.Units.MB:
         return size*1024*1024;
     case FileSizeHelper.Units.GB:
         return size*1024*1024*1024;
     case FileSizeHelper.Units.TB:
         return size*1024*1024*1024*1024;
     case FileSizeHelper.Units.PB:
         throw new NotSupportedException("PetaBytes are not supported",
             new OverflowException(
                 "Only crazy people said computers would be around after the year 2000 now look where we are, How do you even have a file this big?"));
     case FileSizeHelper.Units.EB:
         throw new NotSupportedException("ExaBytes are not supported",
             new OverflowException("How to kill a Mockingbird... I mean server."));
     case FileSizeHelper.Units.ZB:
         throw new NotSupportedException("ZetaBytes are not supported",
             new OverflowException(
                 "For every 1 ZetaByte you upload you get a free PetaByte! Unfortunately, we're out of both."));
     case FileSizeHelper.Units.YB:
         throw new NotSupportedException("YotaBytes are not supported",
             new OverflowException(
                 "We choose to upload YotaBytes in this decade and do the other things, not because they are easy, but because they are hard."));
     default:
         throw new ArgumentOutOfRangeException(nameof(inputUnit));
     }
 }
Exemplo n.º 2
0
 public static long ToBytes(this int size, FileSizeHelper.Units inputUnit) => ToBytes((long) size, inputUnit);