public string ToString(string format, FileSizeSymbolType type = FileSizeSymbolType.Short) { if (format.Equals("b")) { return(this.ConvertToBits(type)); } if (format.Equals("B")) { return(this.ConvertToBytes(type)); } if (format.Equals("KB")) { return(this.ConvertToKiloBytes(type)); } if (format.Equals("MB")) { return(this.ConvertToMegaBytes(type)); } if (format.Equals("GB")) { return(this.ConvertToGigaBytes(type)); } if (format.Equals("TB")) { return(this.ConvertToTeraBytes(type)); } throw new ArgumentException("Provide a valid format parameter."); }
public static string ConvertToBits(this FileSize size, FileSizeSymbolType type) => size.Bits + (type == FileSizeSymbolType.Short ? " b" : " bits");
public static string ConvertToTeraBytes(this FileSize size, FileSizeSymbolType type) => size.Terabytes + (type == FileSizeSymbolType.Short ? " TB" : " terabytes");
public static string ConvertToGigaBytes(this FileSize size, FileSizeSymbolType type) => size.Gigabytes + (type == FileSizeSymbolType.Short ? " GB" : " gigabytes");
public static string ConvertToMegaBytes(this FileSize size, FileSizeSymbolType type) => size.Megabytes + (type == FileSizeSymbolType.Short ? " MB" : " megabytes");
public static string ConvertToKiloBytes(this FileSize size, FileSizeSymbolType type) => size.Kilobytes + (type == FileSizeSymbolType.Short ? " KB" : " kilobytes");
public static string ConvertToBytes(this FileSize size, FileSizeSymbolType type) => size.Bytes + (type == FileSizeSymbolType.Short ? " B" : " bytes");