omar / ByteSize

ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support subtracting two ByteSize objects

omar opened this issue · comments

Support subtracting two ByteSize objects to allow for the following use case:

var quota = ByteSize.FromMegaBytes(20);
var usage = ByteSize.FromMegaBytes(19);
var newFile = ByteSize.FromMegaBytes(2);

if (usage + newFile > quota) {
    var overage = usage + newFile - quota;
    throw new InvalidOperationException($"This file would put you above your quota of { quota } by { overage }");
}