@@ -32,41 +32,93 @@ public int CompareTo(object obj)
32
32
33
33
public static bool operator < ( BaseMoney moneyLeft , BaseMoney moneyRight )
34
34
{
35
+ if ( ReferenceEquals ( moneyLeft , moneyRight ) )
36
+ {
37
+ return false ;
38
+ }
39
+ if ( ReferenceEquals ( moneyLeft , null ) || ReferenceEquals ( moneyRight , null ) )
40
+ {
41
+ return false ;
42
+ }
35
43
return moneyLeft . CompareTo ( moneyRight ) < 0 ;
36
44
}
37
45
38
46
public static bool operator > ( BaseMoney moneyLeft , BaseMoney moneyRight )
39
47
{
48
+ if ( ReferenceEquals ( moneyLeft , moneyRight ) )
49
+ {
50
+ return false ;
51
+ }
52
+ if ( ReferenceEquals ( moneyLeft , null ) || ReferenceEquals ( moneyRight , null ) )
53
+ {
54
+ return false ;
55
+ }
40
56
return moneyLeft . CompareTo ( moneyRight ) > 0 ;
41
57
}
42
58
43
59
public static bool operator <= ( BaseMoney moneyLeft , BaseMoney moneyRight )
44
60
{
61
+ if ( ReferenceEquals ( moneyLeft , moneyRight ) )
62
+ {
63
+ return false ;
64
+ }
65
+ if ( ReferenceEquals ( moneyLeft , null ) || ReferenceEquals ( moneyRight , null ) )
66
+ {
67
+ return false ;
68
+ }
45
69
return moneyLeft . CompareTo ( moneyRight ) <= 0 ;
46
70
}
47
71
48
72
public static bool operator >= ( BaseMoney moneyLeft , BaseMoney moneyRight )
49
73
{
74
+ if ( ReferenceEquals ( moneyLeft , moneyRight ) )
75
+ {
76
+ return false ;
77
+ }
78
+ if ( ReferenceEquals ( moneyLeft , null ) || ReferenceEquals ( moneyRight , null ) )
79
+ {
80
+ return false ;
81
+ }
50
82
return moneyLeft . CompareTo ( moneyRight ) >= 0 ;
51
83
}
52
84
53
85
public static bool operator == ( BaseMoney moneyLeft , BaseMoney moneyRight )
54
86
{
87
+ if ( ReferenceEquals ( moneyLeft , moneyRight ) )
88
+ {
89
+ return true ;
90
+ }
91
+ if ( ReferenceEquals ( moneyLeft , null ) || ReferenceEquals ( moneyRight , null ) )
92
+ {
93
+ return false ;
94
+ }
55
95
return moneyLeft . CompareTo ( moneyRight ) == 0 ;
56
96
}
57
97
58
98
public static bool operator != ( BaseMoney moneyLeft , BaseMoney moneyRight )
59
99
{
100
+ if ( ReferenceEquals ( moneyLeft , moneyRight ) )
101
+ {
102
+ return false ;
103
+ }
104
+ if ( ReferenceEquals ( moneyLeft , null ) || ReferenceEquals ( moneyRight , null ) )
105
+ {
106
+ return true ;
107
+ }
60
108
return moneyLeft . CompareTo ( moneyRight ) != 0 ;
61
109
}
62
110
63
111
public override bool Equals ( object obj )
64
112
{
65
- if ( ! ( obj is BaseMoney money ) )
113
+ if ( ReferenceEquals ( this , obj ) )
66
114
{
67
- throw new ArgumentException ( ) ;
115
+ return true ;
68
116
}
69
- if ( this . CurrencyCode != money . CurrencyCode )
117
+ if ( ReferenceEquals ( obj , null ) || ReferenceEquals ( this , null ) )
118
+ {
119
+ return false ;
120
+ }
121
+ if ( ! ( obj is BaseMoney money ) )
70
122
{
71
123
throw new ArgumentException ( ) ;
72
124
}
0 commit comments