Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ LoadTableFromEnumerable< T >()

static DataTable System.Data.DataTableExtensions.LoadTableFromEnumerable< T > ( IEnumerable< T > source,
DataTable table,
LoadOption? options,
FillErrorEventHandler errorHandler )
inlinestaticprivate
Type Constraints
T :DataRow 

Definition at line 34 of file DataTableExtensions.cs.

34 : DataRow
35 {
36 if (options.HasValue)
37 {
38 LoadOption value = options.Value;
39 if ((uint)(value - 1) > 2u)
40 {
42 }
43 }
45 {
46 if (!enumerator.MoveNext())
47 {
49 }
50 if (table == null)
51 {
52 DataRow current = enumerator.Current;
53 if (current == null)
54 {
56 }
57 table = new DataTable
58 {
59 Locale = CultureInfo.CurrentCulture
60 };
61 foreach (DataColumn column in current.Table.Columns)
62 {
63 table.Columns.Add(column.ColumnName, column.DataType);
64 }
65 }
66 table.BeginLoadData();
67 try
68 {
69 do
70 {
71 DataRow current = enumerator.Current;
72 if (current == null)
73 {
74 continue;
75 }
76 object[] values = null;
77 try
78 {
79 switch (current.RowState)
80 {
81 case DataRowState.Detached:
82 if (!current.HasVersion(DataRowVersion.Proposed))
83 {
85 }
86 goto case DataRowState.Unchanged;
87 case DataRowState.Unchanged:
88 case DataRowState.Added:
89 case DataRowState.Modified:
90 values = current.ItemArray;
91 if (options.HasValue)
92 {
93 table.LoadDataRow(values, options.Value);
94 }
95 else
96 {
97 table.LoadDataRow(values, fAcceptChanges: true);
98 }
99 break;
100 case DataRowState.Deleted:
102 default:
103 throw DataSetUtil.InvalidDataRowState(current.RowState);
104 }
105 }
106 catch (Exception ex)
107 {
109 {
110 throw;
111 }
112 FillErrorEventArgs fillErrorEventArgs = null;
113 if (errorHandler != null)
114 {
115 fillErrorEventArgs = new FillErrorEventArgs(table, values)
116 {
117 Errors = ex
118 };
120 }
121 if (fillErrorEventArgs == null)
122 {
123 throw;
124 }
125 if (!fillErrorEventArgs.Continue)
126 {
127 if ((fillErrorEventArgs.Errors ?? ex) == ex)
128 {
129 throw;
130 }
131 throw fillErrorEventArgs.Errors;
132 }
133 }
134 }
135 while (enumerator.MoveNext());
136 }
137 finally
138 {
139 table.EndLoadData();
140 }
141 }
142 return table;
143 }
static ArgumentOutOfRangeException InvalidDataRowState(DataRowState value)
static InvalidOperationException InvalidOperation(string message)
static ArgumentOutOfRangeException InvalidLoadOption(LoadOption value)
static bool IsCatchableExceptionType(Exception e)
static string DataSetLinq_CannotLoadDetachedRow
Definition SR.cs:930
static string DataSetLinq_CannotLoadDeletedRow
Definition SR.cs:934
static string DataSetLinq_NullDataRow
Definition SR.cs:928
static string DataSetLinq_EmptyDataRowSource
Definition SR.cs:926
Definition SR.cs:7

References System.Data.DataColumnCollection.Add(), System.Data.DataTable.Columns, System.SR.DataSetLinq_CannotLoadDeletedRow, System.SR.DataSetLinq_CannotLoadDetachedRow, System.SR.DataSetLinq_EmptyDataRowSource, System.SR.DataSetLinq_NullDataRow, System.Collections.Generic.Dictionary< TKey, TValue >.GetEnumerator(), System.Data.DataRow.HasVersion(), DataSetUtil.InvalidDataRowState(), DataSetUtil.InvalidLoadOption(), DataSetUtil.InvalidOperation(), DataSetUtil.IsCatchableExceptionType(), System.Data.DataRow.ItemArray, System.options, System.Data.DataRow.RowState, System.source, System.value, and System.values.