Skip to content

Commit e29e96b

Browse files
authored
Code review (#12)
* X500 distinguished name formatting changes * Minor changes to string quoting * Formatting changes * SHA1 usage changes * Formatting changes * Use the decimal data type instead of the double data type
1 parent 8a717de commit e29e96b

14 files changed

+151
-356
lines changed

src/facturae/DataType/DoubleFourDecimalType.cs

+19-66
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace FacturaE.DataType;
99

1010
public struct DoubleFourDecimalType
11-
: IComparable, IFormattable, IConvertible, IComparable<double>, IEquatable<double>, IXmlSerializable
11+
: IComparable, IFormattable, IConvertible, IComparable<decimal>, IEquatable<decimal>, IXmlSerializable
1212
{
13-
public static readonly DoubleFourDecimalType MaxValue = new(double.MaxValue);
14-
public static readonly DoubleFourDecimalType MinValue = new(double.MinValue);
13+
public static readonly DoubleFourDecimalType MaxValue = new(decimal.MaxValue);
14+
public static readonly DoubleFourDecimalType MinValue = new(decimal.MinValue);
1515

1616
public static bool GreaterThan(DoubleFourDecimalType left, DoubleFourDecimalType right)
1717
{
@@ -40,102 +40,55 @@ public static bool NotEquals(DoubleFourDecimalType left, DoubleFourDecimalType r
4040

4141
public static DoubleFourDecimalType Parse(string value)
4242
{
43-
return new DoubleFourDecimalType(double.Parse(value));
43+
return new DoubleFourDecimalType(decimal.Parse(value));
4444
}
4545

4646
public static bool operator ==(DoubleFourDecimalType left, DoubleFourDecimalType right)
4747
{
48-
bool equals = false;
49-
50-
if (left.Value == right.Value)
51-
{
52-
equals = true;
53-
}
54-
55-
return equals;
48+
return left.Value == right.Value;
5649
}
5750

5851
public static bool operator !=(DoubleFourDecimalType left, DoubleFourDecimalType right)
5952
{
60-
bool notequals = false;
61-
62-
if (left.Value != right.Value)
63-
{
64-
notequals = true;
65-
}
66-
67-
return notequals;
53+
return left.Value != right.Value;
6854
}
6955

7056
public static bool operator >(DoubleFourDecimalType left, DoubleFourDecimalType right)
7157
{
72-
bool greater = false;
73-
74-
if (left.Value > right.Value)
75-
{
76-
greater = true;
77-
}
78-
79-
return greater;
58+
return left.Value > right.Value;
8059
}
8160

8261
public static bool operator >=(DoubleFourDecimalType left, DoubleFourDecimalType right)
8362
{
84-
bool greater = false;
85-
86-
if (left.Value >= right.Value)
87-
{
88-
greater = true;
89-
}
90-
91-
return greater;
63+
return left.Value >= right.Value;
9264
}
9365

9466
public static bool operator <(DoubleFourDecimalType left, DoubleFourDecimalType right)
9567
{
96-
bool less = false;
97-
98-
if (left.Value < right.Value)
99-
{
100-
less = true;
101-
}
102-
103-
return less;
68+
return left.Value < right.Value;
10469
}
10570

10671
public static bool operator <=(DoubleFourDecimalType left, DoubleFourDecimalType right)
10772
{
108-
bool less = false;
109-
110-
if (left.Value <= right.Value)
111-
{
112-
less = true;
113-
}
114-
115-
return less;
73+
return left.Value <= right.Value;
11674
}
11775

118-
public static implicit operator double(DoubleFourDecimalType x)
76+
public static implicit operator decimal(DoubleFourDecimalType x)
11977
{
12078
return x.Value;
12179
}
12280

123-
public static implicit operator DoubleFourDecimalType(double x)
81+
public static implicit operator DoubleFourDecimalType(decimal x)
12482
{
12583
return new DoubleFourDecimalType(x);
12684
}
12785

12886
[XmlIgnore]
129-
public double Value { get; private set; }
130-
131-
public DoubleFourDecimalType(double value)
132-
{
133-
Value = value;
134-
}
87+
public decimal Value { get; private set; }
13588

13689
public DoubleFourDecimalType(decimal value)
13790
{
138-
Value = (double)value;
91+
Value = value;
13992
}
14093

14194
public override readonly int GetHashCode()
@@ -195,12 +148,12 @@ readonly DateTime IConvertible.ToDateTime(IFormatProvider provider)
195148

196149
readonly decimal IConvertible.ToDecimal(IFormatProvider provider)
197150
{
198-
return Convert.ToDecimal(Value);
151+
return Value;
199152
}
200153

201154
readonly double IConvertible.ToDouble(IFormatProvider provider)
202155
{
203-
return Value;
156+
return Convert.ToDouble(Value);
204157
}
205158

206159
readonly short IConvertible.ToInt16(IFormatProvider provider)
@@ -253,12 +206,12 @@ readonly ulong IConvertible.ToUInt64(IFormatProvider provider)
253206
return Convert.ToUInt64(Value);
254207
}
255208

256-
readonly int IComparable<double>.CompareTo(double other)
209+
readonly int IComparable<decimal>.CompareTo(decimal other)
257210
{
258211
return CompareTo(other);
259212
}
260213

261-
public readonly bool Equals(double other)
214+
public readonly bool Equals(decimal other)
262215
{
263216
return Equals(other);
264217
}
@@ -272,7 +225,7 @@ public void ReadXml(XmlReader reader)
272225
{
273226
if (reader is not null)
274227
{
275-
Value = reader.ReadElementContentAsDouble();
228+
Value = reader.ReadElementContentAsDecimal();
276229
}
277230
}
278231

src/facturae/DataType/DoubleSixDecimalType.cs

+19-66
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace FacturaE.DataType;
99

1010
public struct DoubleSixDecimalType
11-
: IComparable, IFormattable, IConvertible, IComparable<double>, IEquatable<double>, IXmlSerializable
11+
: IComparable, IFormattable, IConvertible, IComparable<decimal>, IEquatable<decimal>, IXmlSerializable
1212
{
13-
public static readonly DoubleSixDecimalType MaxValue = new(double.MaxValue);
14-
public static readonly DoubleSixDecimalType MinValue = new(double.MinValue);
13+
public static readonly DoubleSixDecimalType MaxValue = new(decimal.MaxValue);
14+
public static readonly DoubleSixDecimalType MinValue = new(decimal.MinValue);
1515

1616
public static bool GreaterThan(DoubleSixDecimalType left, DoubleSixDecimalType right)
1717
{
@@ -40,87 +40,45 @@ public static bool NotEquals(DoubleSixDecimalType left, DoubleSixDecimalType rig
4040

4141
public static DoubleSixDecimalType Parse(string value)
4242
{
43-
return new DoubleSixDecimalType(double.Parse(value));
43+
return new DoubleSixDecimalType(decimal.Parse(value));
4444
}
4545

4646
public static bool operator ==(DoubleSixDecimalType left, DoubleSixDecimalType right)
4747
{
48-
bool equals = false;
49-
50-
if (left.Value == right.Value)
51-
{
52-
equals = true;
53-
}
54-
55-
return equals;
48+
return left.Value == right.Value;
5649
}
5750

5851
public static bool operator !=(DoubleSixDecimalType left, DoubleSixDecimalType right)
5952
{
60-
bool notequals = false;
61-
62-
if (left.Value != right.Value)
63-
{
64-
notequals = true;
65-
}
66-
67-
return notequals;
53+
return left.Value != right.Value;
6854
}
6955

7056
public static bool operator >(DoubleSixDecimalType left, DoubleSixDecimalType right)
7157
{
72-
bool greater = false;
73-
74-
if (left.Value > right.Value)
75-
{
76-
greater = true;
77-
}
78-
79-
return greater;
58+
return left.Value > right.Value;
8059
}
8160

8261
public static bool operator >=(DoubleSixDecimalType left, DoubleSixDecimalType right)
8362
{
84-
bool greater = false;
85-
86-
if (left.Value >= right.Value)
87-
{
88-
greater = true;
89-
}
90-
91-
return greater;
63+
return left.Value >= right.Value;
9264
}
9365

9466
public static bool operator <(DoubleSixDecimalType left, DoubleSixDecimalType right)
9567
{
96-
bool less = false;
97-
98-
if (left.Value < right.Value)
99-
{
100-
less = true;
101-
}
102-
103-
return less;
68+
return left.Value < right.Value;
10469
}
10570

10671
public static bool operator <=(DoubleSixDecimalType left, DoubleSixDecimalType right)
10772
{
108-
bool less = false;
109-
110-
if (left.Value <= right.Value)
111-
{
112-
less = true;
113-
}
114-
115-
return less;
73+
return left.Value <= right.Value;
11674
}
11775

118-
public static implicit operator double(DoubleSixDecimalType x)
76+
public static implicit operator decimal(DoubleSixDecimalType x)
11977
{
12078
return x.Value;
12179
}
12280

123-
public static implicit operator DoubleSixDecimalType(double x)
81+
public static implicit operator DoubleSixDecimalType(decimal x)
12482
{
12583
return new DoubleSixDecimalType(x);
12684
}
@@ -131,16 +89,11 @@ public static implicit operator DoubleSixDecimalType(DoubleTwoDecimalType x)
13189
}
13290

13391
[XmlIgnore]
134-
public double Value { get; private set; }
135-
136-
public DoubleSixDecimalType(double value)
137-
{
138-
Value = value;
139-
}
92+
public decimal Value { get; private set; }
14093

14194
public DoubleSixDecimalType(decimal value)
14295
{
143-
Value = (double)value;
96+
Value = value;
14497
}
14598

14699
public override readonly int GetHashCode()
@@ -200,12 +153,12 @@ readonly DateTime IConvertible.ToDateTime(IFormatProvider provider)
200153

201154
readonly decimal IConvertible.ToDecimal(IFormatProvider provider)
202155
{
203-
return Convert.ToDecimal(Value);
156+
return Value;
204157
}
205158

206159
readonly double IConvertible.ToDouble(IFormatProvider provider)
207160
{
208-
return Value;
161+
return Convert.ToDouble(Value);
209162
}
210163

211164
readonly short IConvertible.ToInt16(IFormatProvider provider)
@@ -258,12 +211,12 @@ readonly ulong IConvertible.ToUInt64(IFormatProvider provider)
258211
return Convert.ToUInt64(Value);
259212
}
260213

261-
readonly int IComparable<double>.CompareTo(double other)
214+
readonly int IComparable<decimal>.CompareTo(decimal other)
262215
{
263216
return CompareTo(other);
264217
}
265218

266-
public readonly bool Equals(double other)
219+
public readonly bool Equals(decimal other)
267220
{
268221
return Equals(other);
269222
}
@@ -277,7 +230,7 @@ public void ReadXml(XmlReader reader)
277230
{
278231
if (reader is not null)
279232
{
280-
Value = reader.ReadElementContentAsDouble();
233+
Value = reader.ReadElementContentAsDecimal();
281234
}
282235
}
283236

0 commit comments

Comments
 (0)