forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonetaryAmount.cs
85 lines (70 loc) · 1.79 KB
/
MonetaryAmount.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
namespace NHibernate.Test.SqlTest
{
[Serializable]
public class MonetaryAmount : IComparable
{
private decimal value;
private string currency;
public MonetaryAmount(decimal value, string currency)
{
this.value = value;
this.currency = currency;
}
public string Currency
{
get { return currency; }
}
public decimal Value
{
get { return value; }
}
// ********************** Common Methods ********************** //
public override bool Equals(Object o)
{
if (this == o)
return true;
if (!(o is MonetaryAmount))
return false;
MonetaryAmount monetaryAmount = (MonetaryAmount) o;
if (!currency.Equals(monetaryAmount.currency))
return false;
if (!value.Equals(monetaryAmount.value))
return false;
return true;
}
public override int GetHashCode()
{
int result;
result = value.GetHashCode();
result = 29 * result + currency.GetHashCode();
return result;
}
public override string ToString()
{
return "Value: '" + Value + "', " +
"Currency: '" + Currency + "'";
}
public int CompareTo(Object o)
{
if (o is MonetaryAmount)
{
// TODO: This would actually require some currency conversion magic
return Value.CompareTo(((MonetaryAmount) o).Value);
}
return 0;
}
// ********************** Business Methods ********************** //
public static MonetaryAmount FromString(string amount, string currencyCode)
{
return new MonetaryAmount(decimal.Parse(amount),
currencyCode);
}
public static MonetaryAmount Convert(MonetaryAmount amount,
string toCurrency)
{
// TODO: This requires some conversion magic and is therefore broken
return new MonetaryAmount(amount.Value, toCurrency);
}
}
}