Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataRowView.cs
Go to the documentation of this file.
3
4namespace System.Data;
5
7{
8 private readonly DataView _dataView;
9
10 private readonly DataRow _row;
11
12 private bool _delayBeginEdit;
13
15
17
18 public object this[int ndx]
19 {
20 get
21 {
22 return Row[ndx, RowVersionDefault];
23 }
24 [param: AllowNull]
25 set
26 {
27 if (!_dataView.AllowEdit && !IsNew)
28 {
30 }
32 }
33 }
34
35 public object this[string property]
36 {
37 get
38 {
39 DataColumn dataColumn = _dataView.Table.Columns[property];
40 if (dataColumn != null)
41 {
42 return Row[dataColumn, RowVersionDefault];
43 }
45 {
46 return CreateChildView(property);
47 }
49 }
50 [param: AllowNull]
51 set
52 {
53 DataColumn dataColumn = _dataView.Table.Columns[property];
54 if (dataColumn == null)
55 {
56 throw ExceptionBuilder.SetFailed(property);
57 }
58 if (!_dataView.AllowEdit && !IsNew)
59 {
61 }
62 SetColumnValue(dataColumn, value);
63 }
64 }
65
66 string IDataErrorInfo.this[string colName] => Row.GetColumnError(colName);
67
68 string IDataErrorInfo.Error => Row.RowError;
69
71
73
74 public DataRow Row => _row;
75
76 public bool IsNew => _row == _dataView._addNewRow;
77
78 public bool IsEdit
79 {
80 get
81 {
82 if (!Row.HasVersion(DataRowVersion.Proposed))
83 {
84 return _delayBeginEdit;
85 }
86 return true;
87 }
88 }
89
90 public event PropertyChangedEventHandler? PropertyChanged;
91
92 internal DataRowView(DataView dataView, DataRow row)
93 {
94 _dataView = dataView;
95 _row = row;
96 }
97
98 public override bool Equals(object? other)
99 {
100 return this == other;
101 }
102
103 public override int GetHashCode()
104 {
105 return Row.GetHashCode();
106 }
107
108 internal int GetRecord()
109 {
111 }
112
113 internal bool HasRecord()
114 {
116 }
117
118 internal object GetColumnValue(DataColumn column)
119 {
120 return Row[column, RowVersionDefault];
121 }
122
123 internal void SetColumnValue(DataColumn column, object value)
124 {
125 if (_delayBeginEdit)
126 {
127 _delayBeginEdit = false;
128 Row.BeginEdit();
129 }
130 if (DataRowVersion.Original == RowVersionDefault)
131 {
133 }
134 Row[column] = value;
135 }
136
137 public DataView CreateChildView(DataRelation relation, bool followParent)
138 {
139 if (relation == null || relation.ParentKey.Table != DataView.Table)
140 {
142 }
143 RelatedView relatedView;
144 if (!followParent)
145 {
146 int record = GetRecord();
147 object[] keyValues = relation.ParentKey.GetKeyValues(record);
148 relatedView = new RelatedView(relation.ChildColumnsReference, keyValues);
149 }
150 else
151 {
152 relatedView = new RelatedView(this, relation.ParentKey, relation.ChildColumnsReference);
153 }
154 relatedView.SetIndex("", DataViewRowState.CurrentRows, null);
156 return relatedView;
157 }
158
160 {
161 return CreateChildView(relation, followParent: false);
162 }
163
164 public DataView CreateChildView(string relationName, bool followParent)
165 {
166 return CreateChildView(DataView.Table.ChildRelations[relationName], followParent);
167 }
168
169 public DataView CreateChildView(string relationName)
170 {
171 return CreateChildView(relationName, followParent: false);
172 }
173
174 public void BeginEdit()
175 {
176 _delayBeginEdit = true;
177 }
178
179 public void CancelEdit()
180 {
181 DataRow row = Row;
182 if (IsNew)
183 {
184 _dataView.FinishAddNew(success: false);
185 }
186 else
187 {
188 row.CancelEdit();
189 }
190 _delayBeginEdit = false;
191 }
192
193 public void EndEdit()
194 {
195 if (IsNew)
196 {
197 _dataView.FinishAddNew(success: true);
198 }
199 else
200 {
201 Row.EndEdit();
202 }
203 _delayBeginEdit = false;
204 }
205
206 public void Delete()
207 {
209 }
210
211 internal void RaisePropertyChangedEvent(string propName)
212 {
213 this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
214 }
215
220
222 {
223 return null;
224 }
225
227 {
228 return null;
229 }
230
231 [RequiresUnreferencedCode("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")]
233 {
234 return null;
235 }
236
237 [RequiresUnreferencedCode("The built-in EventDescriptor implementation uses Reflection which requires unreferenced code.")]
242
243 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
248
249 [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")]
250 object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
251 {
252 return null;
253 }
254
259
260 [RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
265
266 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
268 {
269 return ((ICustomTypeDescriptor)this).GetProperties((Attribute[]?)null);
270 }
271
272 [RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
281
283 {
284 return this;
285 }
286}
DataColumn[] ChildColumnsReference
DataRowVersion RowVersionDefault
DataView CreateChildView(string relationName)
PropertyChangedEventHandler? PropertyChanged
DataView CreateChildView(DataRelation relation, bool followParent)
readonly DataRow _row
readonly DataView _dataView
Definition DataRowView.cs:8
void RaisePropertyChangedEvent(string propName)
DataView CreateChildView(DataRelation relation)
DataRowVersion RowVersion
void SetColumnValue(DataColumn column, object value)
override int GetHashCode()
DataRowView(DataView dataView, DataRow row)
object GetColumnValue(DataColumn column)
static readonly PropertyDescriptorCollection s_zeroPropertyDescriptorCollection
override bool Equals(object? other)
DataView CreateChildView(string relationName, bool followParent)
string GetColumnError(int columnIndex)
Definition DataRow.cs:625
bool HasVersion(DataRowVersion version)
Definition DataRow.cs:941
int GetRecordFromVersion(DataRowVersion version)
Definition DataRow.cs:863
DataRowVersion GetDefaultRowVersion(DataViewRowState viewState)
Definition DataRow.cs:875
DataRelationCollection Relations
Definition DataSet.cs:393
PropertyDescriptorCollection GetPropertyDescriptorCollection(Attribute[] attributes)
DataColumnCollection Columns
Definition DataTable.cs:327
DataRelationCollection ChildRelations
Definition DataTable.cs:324
DataViewRowState RowStateFilter
Definition DataView.cs:254
void Delete(int index)
Definition DataView.cs:671
void SetDataViewManager(DataViewManager dataViewManager)
Definition DataView.cs:1299
void FinishAddNew(bool success)
Definition DataView.cs:775
DataViewManager? DataViewManager
Definition DataView.cs:190
static Exception CreateChildView()
static Exception PropertyNotFound(string property, string table)
static Exception SetFailed(object value, DataColumn column, Type type, Exception innerException)
override void SetIndex(string newSort, DataViewRowState newRowStates, IFilter newRowFilter)
object? GetEditor(Type editorBaseType)
object? GetPropertyOwner(PropertyDescriptor? pd)
PropertyDescriptorCollection GetProperties()
EventDescriptorCollection GetEvents()
object[] GetKeyValues(int record)
Definition DataKey.cs:174
DataTable Table
Definition DataKey.cs:11