cs-codex-dist-tests/DistTestCore/ByteSize.cs

63 lines
1.3 KiB
C#
Raw Normal View History

2023-04-12 11:53:55 +00:00
namespace DistTestCore
{
public class ByteSize
{
public ByteSize(long sizeInBytes)
{
SizeInBytes = sizeInBytes;
}
public long SizeInBytes { get; }
2023-04-19 07:57:37 +00:00
public override string ToString()
{
return $"{SizeInBytes} bytes";
}
2023-04-12 11:53:55 +00:00
}
public static class ByteSizeIntExtensions
2023-04-12 11:53:55 +00:00
{
private const long Kilo = 1024;
public static ByteSize KB(this long i)
{
return new ByteSize(i * Kilo);
}
public static ByteSize MB(this long i)
{
return (i * Kilo).KB();
}
public static ByteSize GB(this long i)
{
return (i * Kilo).MB();
}
public static ByteSize TB(this long i)
{
return (i * Kilo).GB();
}
public static ByteSize KB(this int i)
{
return Convert.ToInt64(i).KB();
}
public static ByteSize MB(this int i)
{
return Convert.ToInt64(i).MB();
}
public static ByteSize GB(this int i)
{
return Convert.ToInt64(i).GB();
}
public static ByteSize TB(this int i)
{
return Convert.ToInt64(i).TB();
}
}
}