main
 1using System.Collections.Generic;
 2using gorilla.commons.utility;
 3using System.Linq;
 4
 5namespace presentation.windows.server.domain.accounting
 6{
 7    public class Currency : SimpleUnitOfMeasure
 8    {
 9        static public readonly List<Currency> all = new List<Currency>();
10        static public readonly Currency USD = new Currency("USD");
11        static public readonly Currency CAD = new Currency("CAD");
12
13        Currency(string pneumonic)
14        {
15            this.pneumonic = pneumonic;
16            all.add(this);
17        }
18
19        public override string pretty_print(double amount)
20        {
21            return "{0:C} {1}".format(amount, this);
22        }
23
24        public bool Equals(Currency other)
25        {
26            if (ReferenceEquals(null, other)) return false;
27            if (ReferenceEquals(this, other)) return true;
28            return Equals(other.pneumonic, pneumonic);
29        }
30
31        public override bool Equals(object obj)
32        {
33            if (ReferenceEquals(null, obj)) return false;
34            if (ReferenceEquals(this, obj)) return true;
35            if (obj.GetType() != typeof (Currency)) return false;
36            return Equals((Currency) obj);
37        }
38
39        public override int GetHashCode()
40        {
41            return (pneumonic != null ? pneumonic.GetHashCode() : 0);
42        }
43
44        static public bool operator ==(Currency left, Currency right)
45        {
46            return Equals(left, right);
47        }
48
49        static public bool operator !=(Currency left, Currency right)
50        {
51            return !Equals(left, right);
52        }
53
54        public override string ToString()
55        {
56            return pneumonic;
57        }
58
59        string pneumonic;
60
61        static public UnitOfMeasure named(string currency)
62        {
63            return all.Single(x => x.pneumonic.Equals(currency));
64        }
65    }
66}