• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JaCraig / Archivist / 22941629001

11 Mar 2026 07:28AM UTC coverage: 77.516% (+0.6%) from 76.939%
22941629001

push

github

web-flow
Merge pull request #286 from JaCraig/dependabot/nuget/Archivist/dependencies-72be12f8a5

chore: Bump the dependencies group with 5 updates

2419 of 3414 branches covered (70.86%)

Branch coverage included in aggregate %.

3204 of 3840 relevant lines covered (83.44%)

3964.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.89
/Archivist/DataTypes/TableRow.cs
1
using Archivist.Interfaces;
2
using ObjectCartographer;
3
using System;
4
using System.Collections;
5
using System.Collections.Generic;
6
using System.Dynamic;
7

8
namespace Archivist.DataTypes
9
{
10
    /// <summary>
11
    /// Represents a table row.
12
    /// </summary>
13
    public class TableRow : IComparable<TableRow>, IEquatable<TableRow>, IObjectConvertable, IList<TableCell>
14
    {
15
        /// <summary>
16
        /// Initializes a new instance of the <see cref="TableRow"/> class with the specified columns.
17
        /// </summary>
18
        /// <param name="columns">The list of column names.</param>
19
        public TableRow(List<string>? columns)
329,356✔
20
        {
21
            Columns = columns ?? new List<string>();
329,356✔
22
        }
329,356✔
23

24
        /// <summary>
25
        /// Gets the number of cells in the row.
26
        /// </summary>
27
        public int Count => Cells.Count;
162✔
28

29
        /// <summary>
30
        /// Gets a value indicating whether the row is read-only.
31
        /// </summary>
32
        public bool IsReadOnly => false;
2✔
33

34
        /// <summary>
35
        /// Gets the list of cells in the row.
36
        /// </summary>
37
        private List<TableCell> Cells { get; } = new List<TableCell>();
1,627,154✔
38

39
        /// <summary>
40
        /// Gets the list of column names.
41
        /// </summary>
42
        private List<string> Columns { get; }
101✔
43

44
        /// <summary>
45
        /// Gets or sets the cell at the specified index.
46
        /// </summary>
47
        /// <param name="index">The index of the cell.</param>
48
        /// <returns>The cell at the specified index.</returns>
49
        public TableCell this[int index]
50
        {
51
            get
52
            {
53
                if (index < 0 || index >= Count)
36✔
54
                    throw new ArgumentOutOfRangeException(nameof(index));
1✔
55
                return Cells[index];
35✔
56
            }
57
            set
58
            {
59
                if (index < 0 || index >= Count)
2✔
60
                    throw new ArgumentOutOfRangeException(nameof(index));
1✔
61
                Cells[index] = value;
1✔
62
            }
1✔
63
        }
64

65
        /// <summary>
66
        /// Gets or sets the cell with the specified column name.
67
        /// </summary>
68
        /// <param name="column">The name of the column.</param>
69
        /// <returns>The cell with the specified column name.</returns>
70
        public TableCell this[string column]
71
        {
72
            get
73
            {
74
                if (string.IsNullOrEmpty(column))
86✔
75
                    return TableCell.Empty;
1✔
76
                var ColumnIndex = Columns.IndexOf(column);
85✔
77
                if (ColumnIndex == -1)
85!
78
                    throw new ArgumentOutOfRangeException(nameof(column));
×
79
                return Cells[ColumnIndex];
85✔
80
            }
81
            set
82
            {
83
                if (string.IsNullOrEmpty(column))
2✔
84
                    return;
1✔
85
                var ColumnIndex = Columns.IndexOf(column);
1✔
86
                if (ColumnIndex == -1)
1!
87
                    throw new ArgumentOutOfRangeException(nameof(column));
×
88
                Cells[ColumnIndex] = value;
1✔
89
            }
1✔
90
        }
91

92
        /// <summary>
93
        /// Determines whether two <see cref="TableRow"/> objects are not equal.
94
        /// </summary>
95
        /// <param name="left">The first <see cref="TableRow"/> to compare.</param>
96
        /// <param name="right">The second <see cref="TableRow"/> to compare.</param>
97
        /// <returns>
98
        /// <c>true</c> if the two <see cref="TableRow"/> objects are not equal; otherwise, <c>false</c>.
99
        /// </returns>
100
        public static bool operator !=(TableRow? left, TableRow? right)
101
        {
102
            return !(left == right);
6✔
103
        }
104

105
        /// <summary>
106
        /// Determines whether the first <see cref="TableRow"/> is less than the second <see cref="TableRow"/>.
107
        /// </summary>
108
        /// <param name="left">The first <see cref="TableRow"/> to compare.</param>
109
        /// <param name="right">The second <see cref="TableRow"/> to compare.</param>
110
        /// <returns>
111
        /// <c>true</c> if the first <see cref="TableRow"/> is less than the second <see
112
        /// cref="TableRow"/>; otherwise, <c>false</c>.
113
        /// </returns>
114
        public static bool operator <(TableRow? left, TableRow? right)
115
        {
116
            return left is null ? right is not null : left.CompareTo(right) < 0;
4✔
117
        }
118

119
        /// <summary>
120
        /// Determines whether the first <see cref="TableRow"/> is less than or equal to the second
121
        /// <see cref="TableRow"/>.
122
        /// </summary>
123
        /// <param name="left">The first <see cref="TableRow"/> to compare.</param>
124
        /// <param name="right">The second <see cref="TableRow"/> to compare.</param>
125
        /// <returns>
126
        /// <c>true</c> if the first <see cref="TableRow"/> is less than or equal to the second <see
127
        /// cref="TableRow"/>; otherwise, <c>false</c>.
128
        /// </returns>
129
        public static bool operator <=(TableRow? left, TableRow? right)
130
        {
131
            return left is null || left.CompareTo(right) <= 0;
4✔
132
        }
133

134
        /// <summary>
135
        /// Determines whether two <see cref="TableRow"/> objects are equal.
136
        /// </summary>
137
        /// <param name="left">The first <see cref="TableRow"/> to compare.</param>
138
        /// <param name="right">The second <see cref="TableRow"/> to compare.</param>
139
        /// <returns>
140
        /// <c>true</c> if the two <see cref="TableRow"/> objects are equal; otherwise, <c>false</c>.
141
        /// </returns>
142
        public static bool operator ==(TableRow? left, TableRow? right)
143
        {
144
            if (left is null)
12✔
145
                return right is null;
4✔
146
            return left.Equals(right);
8✔
147
        }
148

149
        /// <summary>
150
        /// Determines whether the first <see cref="TableRow"/> is greater than the second <see cref="TableRow"/>.
151
        /// </summary>
152
        /// <param name="left">The first <see cref="TableRow"/> to compare.</param>
153
        /// <param name="right">The second <see cref="TableRow"/> to compare.</param>
154
        /// <returns>
155
        /// <c>true</c> if the first <see cref="TableRow"/> is greater than the second <see
156
        /// cref="TableRow"/>; otherwise, <c>false</c>.
157
        /// </returns>
158
        public static bool operator >(TableRow? left, TableRow? right)
159
        {
160
            return left?.CompareTo(right) > 0;
4✔
161
        }
162

163
        /// <summary>
164
        /// Determines whether the first <see cref="TableRow"/> is greater than or equal to the
165
        /// second <see cref="TableRow"/>.
166
        /// </summary>
167
        /// <param name="left">The first <see cref="TableRow"/> to compare.</param>
168
        /// <param name="right">The second <see cref="TableRow"/> to compare.</param>
169
        /// <returns>
170
        /// <c>true</c> if the first <see cref="TableRow"/> is greater than or equal to the second
171
        /// <see cref="TableRow"/>; otherwise, <c>false</c>.
172
        /// </returns>
173
        public static bool operator >=(TableRow? left, TableRow? right)
174
        {
175
            return left is null ? right is null : left.CompareTo(right) >= 0;
4✔
176
        }
177

178
        /// <summary>
179
        /// Adds a cell to the row.
180
        /// </summary>
181
        /// <param name="item">The cell to add.</param>
182
        public void Add(TableCell? item) => Cells.Add(item ?? new TableCell(""));
217✔
183

184
        /// <summary>
185
        /// Adds a cell to the row with the specified content.
186
        /// </summary>
187
        /// <param name="item">The content of the cell to add.</param>
188
        public void Add(string? item) => Add(new TableCell(item));
190✔
189

190
        /// <summary>
191
        /// Adds a list of cells to the row.
192
        /// </summary>
193
        /// <param name="collection">The list of cells to add.</param>
194
        public void AddRange(IEnumerable<TableCell> collection) => Cells.AddRange(collection ?? Array.Empty<TableCell>());
3✔
195

196
        /// <summary>
197
        /// Adds a list of cells to the row with the specified content.
198
        /// </summary>
199
        /// <param name="collection">The list of content to add.</param>
200
        public void AddRange(IEnumerable<string> collection)
201
        {
202
            if (collection is null)
6✔
203
                return;
1✔
204
            foreach (var Item in collection)
36✔
205
                Add(Item);
13✔
206
        }
5✔
207

208
        /// <summary>
209
        /// Removes all cells from the row.
210
        /// </summary>
211
        public void Clear() => Cells.Clear();
2✔
212

213
        /// <summary>
214
        /// Compares the current <see cref="TableRow"/> with another <see cref="TableRow"/> and
215
        /// returns an integer that indicates whether the current <see cref="TableRow"/> precedes,
216
        /// follows, or occurs in the same position in the sort order as the other <see cref="TableRow"/>.
217
        /// </summary>
218
        /// <param name="other">The <see cref="TableRow"/> to compare with the current <see cref="TableRow"/>.</param>
219
        /// <returns>A value that indicates the relative order of the objects being compared.</returns>
220
        public int CompareTo(TableRow? other)
221
        {
222
            if (other is null)
29✔
223
                return 1;
5✔
224
            if (other.Count != Count)
24!
225
                return Count.CompareTo(other.Count);
×
226
            for (var X = 0; X < Count; ++X)
118✔
227
            {
228
                var TempValue = Cells[X].CompareTo(other.Cells[X]);
41✔
229
                if (TempValue != 0)
41✔
230
                    return TempValue;
6✔
231
            }
232
            return 0;
18✔
233
        }
234

235
        /// <summary>
236
        /// Determines whether the row contains a specific cell.
237
        /// </summary>
238
        /// <param name="item">The cell to locate in the row.</param>
239
        /// <returns><c>true</c> if the cell is found in the row; otherwise, <c>false</c>.</returns>
240
        public bool Contains(TableCell? item) => item is not null && Cells.Contains(item);
3✔
241

242
        /// <summary>
243
        /// Copies the object to the row.
244
        /// </summary>
245
        /// <typeparam name="TObject">The object type</typeparam>
246
        /// <param name="obj">The object to copy.</param>
247
        public void ConvertFrom<TObject>(TObject obj)
248
        {
249
            Cells.Clear();
6✔
250
            if (obj is null)
6✔
251
                return;
1✔
252
            foreach (System.Reflection.PropertyInfo Property in obj.GetType().GetProperties())
24✔
253
            {
254
                var ColumnIndex = Columns.IndexOf(Property.Name);
7✔
255
                if (ColumnIndex == -1)
7!
256
                {
257
                    Columns.Add(Property.Name);
×
258
                    _ = Columns.Count - 1;
×
259
                }
260
                Cells.Add(new TableCell(Property.GetValue(obj)?.ToString() ?? ""));
7!
261
            }
262
        }
5✔
263

264
        /// <summary>
265
        /// Converts the current <see cref="TableRow"/> to an object array of the specified type.
266
        /// </summary>
267
        /// <typeparam name="TObject">The type of the object.</typeparam>
268
        /// <returns>The resulting array.</returns>
269
        public TObject ConvertTo<TObject>()
270
        {
271
            IDictionary<string, object?> TempValue = new ExpandoObject();
5✔
272
            for (var Y = 0; Y < Cells.Count; ++Y)
18✔
273
            {
274
                var ColumnName = Columns.Count > Y ? Columns[Y] : Y.ToString();
4!
275
                TempValue[ColumnName] = Cells[Y].Content;
4✔
276
            }
277
            return TempValue.To<TObject>();
5✔
278
        }
279

280
        /// <summary>
281
        /// Copies the elements of the row to an array, starting at a particular array index.
282
        /// </summary>
283
        /// <param name="array">
284
        /// The one-dimensional array that is the destination of the elements copied from the row.
285
        /// </param>
286
        /// <param name="arrayIndex">
287
        /// The zero-based index in <paramref name="array"/> at which copying begins.
288
        /// </param>
289
        public void CopyTo(TableCell[]? array, int arrayIndex)
290
        {
291
            if (array is null || array.Length == 0)
3✔
292
                return;
2✔
293
            if (arrayIndex < 0 || arrayIndex >= array.Length)
1!
294
                throw new ArgumentOutOfRangeException(nameof(arrayIndex));
×
295
            Cells.CopyTo(array, arrayIndex);
1✔
296
        }
1✔
297

298
        /// <summary>
299
        /// Determines whether the current <see cref="TableRow"/> is equal to another <see cref="TableRow"/>.
300
        /// </summary>
301
        /// <param name="other">The <see cref="TableRow"/> to compare with the current <see cref="TableRow"/>.</param>
302
        /// <returns>
303
        /// <c>true</c> if the two <see cref="TableRow"/> objects are equal; otherwise, <c>false</c>.
304
        /// </returns>
305
        public bool Equals(TableRow? other) => other is not null && CompareTo(other) == 0;
19✔
306

307
        /// <summary>
308
        /// Determines whether the current <see cref="TableRow"/> is equal to another object.
309
        /// </summary>
310
        /// <param name="obj">The object to compare with the current <see cref="TableRow"/>.</param>
311
        /// <returns>
312
        /// <c>true</c> if the object is a <see cref="TableRow"/> and is equal to the current <see
313
        /// cref="TableRow"/>; otherwise, <c>false</c>.
314
        /// </returns>
315
        public override bool Equals(object? obj)
316
        {
317
            if (ReferenceEquals(this, obj))
6!
318
                return true;
×
319
            if (obj is null)
6✔
320
                return false;
2✔
321
            return obj is TableRow TableRowObject && Equals(TableRowObject);
4✔
322
        }
323

324
        /// <summary>
325
        /// Returns an enumerator that iterates through the cells in the row.
326
        /// </summary>
327
        /// <returns>An enumerator that can be used to iterate through the cells in the row.</returns>
328
        public IEnumerator GetEnumerator() => Cells.GetEnumerator();
12✔
329

330
        /// <summary>
331
        /// Returns the enumerator that iterates through the cells in the row.
332
        /// </summary>
333
        /// <returns>An enumerator that can be used to iterate through the cells in the row.</returns>
334
        IEnumerator<TableCell> IEnumerable<TableCell>.GetEnumerator() => Cells.GetEnumerator();
1,297,092✔
335

336
        /// <summary>
337
        /// Returns the hash code for the row.
338
        /// </summary>
339
        /// <returns>A 32-bit signed integer hash code.</returns>
340
        public override int GetHashCode()
341
        {
342
            var HashCode = new HashCode();
14✔
343
            foreach (TableCell Cell in Cells)
52✔
344
                HashCode.Add(Cell);
12✔
345
            return HashCode.ToHashCode();
14✔
346
        }
347

348
        /// <summary>
349
        /// Searches for the specified cell and returns the zero-based index of the first occurrence
350
        /// within the entire row.
351
        /// </summary>
352
        /// <param name="item">The cell to locate in the row.</param>
353
        /// <returns>
354
        /// The zero-based index of the first occurrence of the cell within the entire row, if
355
        /// found; otherwise, -1.
356
        /// </returns>
357
        public int IndexOf(TableCell? item) => Cells.IndexOf(item ?? TableCell.Empty);
3✔
358

359
        /// <summary>
360
        /// Inserts a cell into the row at the specified index.
361
        /// </summary>
362
        /// <param name="index">The zero-based index at which the cell should be inserted.</param>
363
        /// <param name="item">The cell to insert into the row.</param>
364
        public void Insert(int index, TableCell? item)
365
        {
366
            if (index < 0 || index > Count)
3!
367
                throw new ArgumentOutOfRangeException(nameof(index));
×
368
            Cells.Insert(index, item ?? new TableCell(""));
3✔
369
        }
3✔
370

371
        /// <summary>
372
        /// Removes the first occurrence of a specific cell from the row.
373
        /// </summary>
374
        /// <param name="item">The cell to remove from the row.</param>
375
        /// <returns><c>true</c> if the cell is successfully removed; otherwise, <c>false</c>.</returns>
376
        public bool Remove(TableCell? item) => item is not null && Cells.Remove(item);
3✔
377

378
        /// <summary>
379
        /// Removes the cell at the specified index from the row.
380
        /// </summary>
381
        /// <param name="index">The zero-based index of the cell to remove.</param>
382
        public void RemoveAt(int index)
383
        {
384
            if (index < 0 || index >= Count)
2!
385
                return;
×
386
            Cells.RemoveAt(index);
2✔
387
        }
2✔
388

389
        /// <summary>
390
        /// Returns a string that represents the row.
391
        /// </summary>
392
        /// <returns>A string that represents the row.</returns>
393
        public override string ToString() => string.Join(' ', Cells);
55✔
394
    }
395
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc