Skip to content

Commit 6dcb564

Browse files
hyperia-forex: disable
1 parent 60609e2 commit 6dcb564

File tree

1 file changed

+90
-4
lines changed

1 file changed

+90
-4
lines changed
Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
#pragma warning disable CS0660
5+
#pragma warning disable CS0661
6+
17
public struct CurrencyAmount
28
{
39
private decimal amount;
@@ -9,11 +15,91 @@ public CurrencyAmount(decimal amount, string currency)
915
this.currency = currency;
1016
}
1117

12-
// TODO: implement equality operators
18+
public static bool operator ==(CurrencyAmount @this, CurrencyAmount other)
19+
{
20+
if (@this.currency != other.currency)
21+
{
22+
throw new ArgumentException();
23+
}
24+
25+
return @this.amount == other.amount;
26+
}
27+
28+
public static bool operator !=(CurrencyAmount @this, CurrencyAmount other)
29+
{
30+
if (@this.currency != other.currency)
31+
{
32+
throw new ArgumentException();
33+
}
34+
35+
return @this.amount != other.amount;
36+
}
37+
38+
public static bool operator >(CurrencyAmount @this, CurrencyAmount other)
39+
{
40+
if (@this.currency != other.currency)
41+
{
42+
throw new ArgumentException();
43+
}
44+
45+
return @this.amount > other.amount;
46+
}
47+
48+
public static bool operator <(CurrencyAmount @this, CurrencyAmount other)
49+
{
50+
if (@this.currency != other.currency)
51+
{
52+
throw new ArgumentException();
53+
}
54+
55+
return @this.amount < other.amount;
56+
}
57+
58+
public static CurrencyAmount operator +(CurrencyAmount @this, CurrencyAmount other)
59+
{
60+
if (@this.currency != other.currency)
61+
{
62+
throw new ArgumentException();
63+
}
64+
65+
return new CurrencyAmount(@this.amount + other.amount, @this.currency);
66+
}
67+
68+
public static CurrencyAmount operator -(CurrencyAmount @this, CurrencyAmount other)
69+
{
70+
if (@this.currency != other.currency)
71+
{
72+
throw new ArgumentException();
73+
}
74+
75+
return new CurrencyAmount(@this.amount - other.amount, @this.currency);
76+
}
1377

14-
// TODO: implement comparison operators
78+
public static CurrencyAmount operator *(CurrencyAmount @this, decimal multiplier)
79+
{
80+
return new CurrencyAmount(@this.amount * multiplier, @this.currency);
81+
}
1582

16-
// TODO: implement arithmetic operators
83+
public static CurrencyAmount operator *(decimal multiplier, CurrencyAmount @this)
84+
{
85+
return new CurrencyAmount(@this.amount * multiplier, @this.currency);
86+
}
1787

18-
// TODO: implement type conversion operators
88+
public static CurrencyAmount operator /(CurrencyAmount @this, decimal divisor)
89+
{
90+
return new CurrencyAmount(@this.amount / divisor, @this.currency);
91+
}
92+
93+
public static explicit operator double(CurrencyAmount @this)
94+
{
95+
return (double)@this.amount;
96+
}
97+
98+
public static implicit operator decimal(CurrencyAmount @this)
99+
{
100+
return @this.amount;
101+
}
19102
}
103+
104+
#pragma warning restore CS0660
105+
#pragma warning restore CS0661

0 commit comments

Comments
 (0)