/// <summary> /// Returns a new <see cref="DecimalSize"/> which is big enough to accomodate decimals of <paramref name="first"/> size and those of <paramref name="second"/>. /// For example if the first is decimal(3,0) and the second is decimal(5,4) then the returned result would be decimal(7,4). /// </summary> /// <param name="first"></param> /// <param name="second"></param> /// <returns></returns> public static DecimalSize Combine(DecimalSize first, DecimalSize second) { if (first == null) { return(second); } if (second == null) { return(first); } var newSize = new DecimalSize(); newSize.IncreaseTo(first); newSize.IncreaseTo(second); return(newSize); }
/// <summary> /// Expands the instance to accomodate the new size (if expansion is required) /// </summary> /// <param name="other"></param> private void IncreaseTo(DecimalSize other) { NumbersBeforeDecimalPlace = Math.Max(NumbersBeforeDecimalPlace, other.NumbersBeforeDecimalPlace); NumbersAfterDecimalPlace = Math.Max(NumbersAfterDecimalPlace, other.NumbersAfterDecimalPlace); }
/// <summary> /// Property based equality /// </summary> /// <param name="other"></param> /// <returns></returns> protected bool Equals(DecimalSize other) { return(NumbersBeforeDecimalPlace == other.NumbersBeforeDecimalPlace && NumbersAfterDecimalPlace == other.NumbersAfterDecimalPlace); }