main
 1using System;
 2using gorilla.utility;
 3
 4namespace solidware.financials.service.domain.payroll
 5{
 6    public class Money : IEquatable<Money>
 7    {
 8        decimal value;
 9        static public Money Zero = new Money(0);
10
11        Money(decimal value)
12        {
13            this.value = value;
14        }
15
16        static public implicit operator Money(decimal raw)
17        {
18            return new Money(raw);
19        }
20
21        public virtual Money plus(Money other)
22        {
23            return value + other.value;
24        }
25
26        public virtual Money minus(Money other)
27        {
28            return value - other.value;
29        }
30
31        public virtual bool Equals(Money other)
32        {
33            if (ReferenceEquals(null, other)) return false;
34            if (ReferenceEquals(this, other)) return true;
35            return other.value.Equals(value);
36        }
37
38        public override bool Equals(object obj)
39        {
40            if (ReferenceEquals(null, obj)) return false;
41            if (ReferenceEquals(this, obj)) return true;
42            if (obj.GetType() != typeof (Money)) return false;
43            return Equals((Money) obj);
44        }
45
46        public override int GetHashCode()
47        {
48            return value.GetHashCode();
49        }
50
51        public override string ToString()
52        {
53            return "{0:C}".format(value);
54        }
55
56        public Units at_price(decimal price)
57        {
58            return Units.New((int)(value / price));
59        }
60    }
61}