-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCsvCell.cs
More file actions
111 lines (106 loc) · 3.87 KB
/
Copy pathCsvCell.cs
File metadata and controls
111 lines (106 loc) · 3.87 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using BytecodeApi.Extensions;
namespace BytecodeApi.CsvParser;
/// <summary>
/// Represents a cell in a <see cref="CsvRow" /> of a CSV file.
/// </summary>
public struct CsvCell : IEquatable<CsvCell>
{
/// <summary>
/// Gets or sets the cell content of a CSV file.
/// </summary>
public string Value { get; set; }
/// <summary>
/// Gets or sets the parsed <see cref="int" /> value of the <see cref="Value" /> property. If conversion fails, <see langword="null" /> is returned. Assigning a value sets the <see cref="Value" /> property by converting the value to a <see cref="string" />.
/// </summary>
public int? Int32Value
{
readonly get => Value?.ToInt32OrNull();
set => Value = value?.ToString() ?? "";
}
/// <summary>
/// Gets or sets the parsed <see cref="long" /> value of the <see cref="Value" /> property. If conversion fails, <see langword="null" /> is returned. Assigning a value sets the <see cref="Value" /> property by converting the value to a <see cref="string" />.
/// </summary>
public long? Int64Value
{
readonly get => Value?.ToInt64OrNull();
set => Value = value?.ToString() ?? "";
}
/// <summary>
/// Initializes a new instance of the <see cref="CsvCell" /> structure with the specified value.
/// </summary>
/// <param name="value">The <see cref="string" /> value of this cell.</param>
public CsvCell(string value)
{
Value = value;
}
/// <summary>
/// Returns a <see cref="string" /> whose value was parsed from the CSV file.
/// </summary>
/// <returns>
/// A <see cref="string" /> whose value was parsed from the CSV file.
/// </returns>
public override readonly string ToString()
{
return Value ?? "";
}
/// <summary>
/// Determines whether the specified <see cref="object" /> is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="object" /> to compare with this instance.</param>
/// <returns>
/// <see langword="true" />, if the specified <see cref="object" /> is equal to this instance;
/// otherwise, <see langword="false" />.
/// </returns>
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is CsvCell csvCell && Equals(csvCell);
}
/// <summary>
/// Determines whether this instance is equal to another <see cref="CsvCell" />.
/// </summary>
/// <param name="other">The <see cref="CsvCell" /> to compare to this instance.</param>
/// <returns>
/// <see langword="true" />, if this instance is equal to the <paramref name="other" /> parameter;
/// otherwise, <see langword="false" />.
/// </returns>
public readonly bool Equals(CsvCell other)
{
return Value == other.Value;
}
/// <summary>
/// Returns a hash code for this <see cref="CsvCell" />.
/// </summary>
/// <returns>
/// The hash code for this <see cref="CsvCell" /> instance.
/// </returns>
public override readonly int GetHashCode()
{
return HashCode.Combine(Value);
}
/// <summary>
/// Compares two <see cref="CsvCell" /> instances for equality.
/// </summary>
/// <param name="a">The first <see cref="CsvCell" /> to compare.</param>
/// <param name="b">The second <see cref="CsvCell" /> to compare.</param>
/// <returns>
/// <see langword="true" />, if both <see cref="CsvCell" /> are equal;
/// otherwise, <see langword="false" />.
/// </returns>
public static bool operator ==(CsvCell a, CsvCell b)
{
return Equals(a, b);
}
/// <summary>
/// Compares two <see cref="CsvCell" /> instances for inequality.
/// </summary>
/// <param name="a">The first <see cref="CsvCell" /> to compare.</param>
/// <param name="b">The second <see cref="CsvCell" /> to compare.</param>
/// <returns>
/// <see langword="true" />, if both <see cref="CsvCell" /> are not equal;
/// otherwise, <see langword="false" />.
/// </returns>
public static bool operator !=(CsvCell a, CsvCell b)
{
return !(a == b);
}
}