/// <summary> /// Equals check /// </summary> /// <param name="obj"></param> /// <returns>bool</returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj is MoneyInfo) { MoneyInfo otherObject = (MoneyInfo)obj; if (this._currencyID.HasValue && otherObject._currencyID.HasValue) { return(this._currencyID.Value == otherObject._currencyID.Value && this.Value == otherObject.Value); } else if (!this._currencyID.HasValue && !otherObject._currencyID.HasValue) { return(true); } else { return(false); } } else { throw new ArgumentException("object is not a MoneyInfo"); } }
/// <summary> /// Subtraction operation /// </summary> /// <param name="m1"></param> /// <param name="m2"></param> /// <returns>MoneyInfo</returns> public static MoneyInfo operator -(MoneyInfo m1, MoneyInfo m2) { if (m1 == null || m2 == null) { if (m1 != null) { return(new MoneyInfo(m1.Value, m1.Currency)); } else if (m2 != null) { return(new MoneyInfo(-m2.Value, m2.Currency)); } else { return(null); } } else { if ((m1.CurrencyID == m2.CurrencyID) || (m1.CurrencyID.HasValue && !m2.CurrencyID.HasValue) || (!m1.CurrencyID.HasValue && m2.CurrencyID.HasValue)) { if (!m1.CurrencyID.HasValue) { m1.CurrencyID = m2.CurrencyID; } else if (!m2.CurrencyID.HasValue) { m2.CurrencyID = m1.CurrencyID; } MoneyInfo money = new MoneyInfo(); money.CurrencyID = m1.CurrencyID; money.Value = m1.Value - m2.Value; return(money); } else { throw new Exception("Must have simillar Currencies to calculate correctly"); } } }
/// <summary> /// Comparison operation /// </summary> /// <param name="obj"></param> /// <returns>int</returns> public int CompareTo(object obj) { if (obj is MoneyInfo) { MoneyInfo otherObject = (MoneyInfo)obj; if (this.CurrencyID == otherObject.CurrencyID) { return(this.Value.CompareTo(otherObject.Value)); } else { throw new Exception("Must have simillar Currencies to calculate correctly"); } } else { throw new ArgumentException("object is not a MoneyInfo"); } }