main
1using gorilla.utility;
2using solidware.financials.windows.ui.views.controls;
3
4namespace solidware.financials.windows.ui.presenters
5{
6 public class Money
7 {
8 static public readonly Money Zero = new Money(0m);
9 static public Observable<Money> Null { get { return new ObservableProperty<Money>(Zero); } }
10
11 public Money(decimal money)
12 {
13 this.money = money;
14 }
15 static public implicit operator decimal(Money money)
16 {
17 return money.money;
18 }
19
20 static public implicit operator Money(decimal money)
21 {
22 return new Money(money);
23 }
24
25 public Money Plus(Money other)
26 {
27 return new Money(money + other.money);
28 }
29
30 public bool Equals(Money other)
31 {
32 if (ReferenceEquals(null, other)) return false;
33 if (ReferenceEquals(this, other)) return true;
34 return other.money == money;
35 }
36
37 public override bool Equals(object obj)
38 {
39 if (ReferenceEquals(null, obj)) return false;
40 if (ReferenceEquals(this, obj)) return true;
41 if (obj.GetType() != typeof (Money)) return false;
42 return Equals((Money) obj);
43 }
44
45 public override int GetHashCode()
46 {
47 return money.GetHashCode();
48 }
49
50 public override string ToString()
51 {
52 return "{0:C}".format(money);
53 }
54
55 decimal money;
56 }
57}