forked from florentbr/SeleniumBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableRow.cs
More file actions
107 lines (90 loc) · 3.4 KB
/
TableRow.cs
File metadata and controls
107 lines (90 loc) · 3.4 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
using System;
using System.Collections;
using System.Runtime.InteropServices;
namespace Selenium {
/// <summary>
/// DataRow object
/// </summary>
[ProgId("Selenium.TableRow")]
[Guid("0277FC34-FD1B-4616-BB19-760FA0360E53")]
[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
public class TableRow : ComInterfaces._TableRow {
private System.Data.DataRow _datarow;
private Table _datatable;
internal TableRow(Table datatable, System.Data.DataRow datarow) {
_datatable = datatable;
_datarow = datarow;
}
/// <summary>
/// Gets or sets the value associated with the column identifier
/// </summary>
/// <param name="identifier">Name of the colum or index</param>
/// <returns></returns>
public object this[object identifier] {
get {
int c = GetColumn(identifier);
return _datarow[c];
}
set {
int c = GetColumn(identifier);
_datarow[c] = value;
_datatable.SetCell(_datarow, c, value);
}
}
/// <summary>
/// Gets the value associated with the column identifier
/// </summary>
/// <param name="identifier">Name of the colum or index</param>
/// <returns></returns>
object ComInterfaces._TableRow.Get(object identifier) {
return this[identifier];
}
/// <summary>
/// Sets the value associated with the column identifier
/// </summary>
/// <param name="identifier">Name of the colum or index</param>
/// <param name="value">Value to set</param>
void ComInterfaces._TableRow.Set(object identifier, object value) {
this[identifier] = value;
}
/// <summary>
/// Gets the Excel range if any asscociated with the column identifier
/// </summary>
/// <param name="identifier">Name of the colum or index</param>
/// <returns></returns>
public object Cell(object identifier) {
var table = _datarow.Table;
int r = table.Rows.IndexOf(_datarow);
int c;
if (identifier is string) {
c = table.Columns[(string)identifier].Ordinal;
} else if (identifier is Int16) {
c = (short)identifier - 1;
} else if (identifier is Int32) {
c = (int)identifier - 1;
} else {
throw new Errors.ArgumentError("Invalid data type for argument identifier. Allowed: string, integer");
}
return _datatable.GetCell(r, c);
}
/// <summary>
/// Gets an array containing all the values of the row
/// </summary>
public object Values {
get {
return _datarow.ItemArray;
}
}
#region Internal support methods
private int GetColumn(object identifier) {
if (identifier is string)
return _datarow.Table.Columns[(string)identifier].Ordinal;
if (identifier is Int16)
return (int)(Int16)identifier;
if (identifier is int)
return (int)identifier;
throw new Errors.ArgumentError("Invalid data type for argument identifier. Allowed: string, integer");
}
#endregion
}
}