Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BindingList.cs
Go to the documentation of this file.
7
9
11[TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
13{
14 private int addNewPos = -1;
15
16 private bool raiseListChangedEvents = true;
17
19
22
24 private PropertyChangedEventHandler _propertyChangedEventHandler;
25
27 private AddingNewEventHandler _onAddingNew;
28
30 private ListChangedEventHandler _onListChanged;
31
33 private int _lastChangeIndex = -1;
34
35 private bool allowNew = true;
36
37 private bool allowEdit = true;
38
39 private bool allowRemove = true;
40
41 private bool userSetAllowNew;
42
44 {
45 get
46 {
48 if (typeFromHandle.IsPrimitive)
49 {
50 return true;
51 }
52 return typeFromHandle.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, Type.EmptyTypes, null) != null;
53 }
54 }
55
57 {
58 get
59 {
61 }
62 set
63 {
65 }
66 }
67
68 private bool AddingNewHandled
69 {
70 get
71 {
72 if (_onAddingNew != null)
73 {
74 return _onAddingNew.GetInvocationList().Length != 0;
75 }
76 return false;
77 }
78 }
79
80 public bool AllowNew
81 {
82 get
83 {
85 {
86 return allowNew;
87 }
88 return AddingNewHandled;
89 }
90 set
91 {
92 bool flag = AllowNew;
93 userSetAllowNew = true;
95 if (flag != value)
96 {
98 }
99 }
100 }
101
102 bool IBindingList.AllowNew => AllowNew;
103
104 public bool AllowEdit
105 {
106 get
107 {
108 return allowEdit;
109 }
110 set
111 {
112 if (allowEdit != value)
113 {
116 }
117 }
118 }
119
120 bool IBindingList.AllowEdit => AllowEdit;
121
122 public bool AllowRemove
123 {
124 get
125 {
126 return allowRemove;
127 }
128 set
129 {
130 if (allowRemove != value)
131 {
134 }
135 }
136 }
137
138 bool IBindingList.AllowRemove => AllowRemove;
139
140 bool IBindingList.SupportsChangeNotification => SupportsChangeNotificationCore;
141
142 protected virtual bool SupportsChangeNotificationCore => true;
143
144 bool IBindingList.SupportsSearching => SupportsSearchingCore;
145
146 protected virtual bool SupportsSearchingCore => false;
147
148 bool IBindingList.SupportsSorting => SupportsSortingCore;
149
150 protected virtual bool SupportsSortingCore => false;
151
152 bool IBindingList.IsSorted => IsSortedCore;
153
154 protected virtual bool IsSortedCore => false;
155
156 PropertyDescriptor? IBindingList.SortProperty => SortPropertyCore;
157
158 protected virtual PropertyDescriptor? SortPropertyCore => null;
159
160 ListSortDirection IBindingList.SortDirection => SortDirectionCore;
161
163
164 bool IRaiseItemChangedEvents.RaisesItemChangedEvents => raiseItemChangedEvents;
165
166 public event AddingNewEventHandler AddingNew
167 {
168 add
169 {
170 bool flag = AllowNew;
172 if (flag != AllowNew)
173 {
175 }
176 }
177 remove
178 {
179 bool flag = AllowNew;
181 if (flag != AllowNew)
182 {
184 }
185 }
186 }
187
188 public event ListChangedEventHandler ListChanged
189 {
190 add
191 {
193 }
194 remove
195 {
197 }
198 }
199
200 [RequiresUnreferencedCode("Raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
201 public BindingList()
202 {
203 Initialize();
204 }
205
206 [RequiresUnreferencedCode("Raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
208 : base(list)
209 {
210 Initialize();
211 }
212
213 [RequiresUnreferencedCode("Raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
214 private void Initialize()
215 {
217 if (!typeof(INotifyPropertyChanged).IsAssignableFrom(typeof(T)))
218 {
219 return;
220 }
222 foreach (T item in base.Items)
223 {
225 }
226 }
227
228 protected virtual void OnAddingNew(AddingNewEventArgs e)
229 {
230 _onAddingNew?.Invoke(this, e);
231 }
232
233 private object FireAddingNew()
234 {
237 return addingNewEventArgs.NewObject;
238 }
239
240 protected virtual void OnListChanged(ListChangedEventArgs e)
241 {
242 _onListChanged?.Invoke(this, e);
243 }
244
245 public void ResetBindings()
246 {
248 }
249
250 public void ResetItem(int position)
251 {
252 FireListChanged(ListChangedType.ItemChanged, position);
253 }
254
256 {
258 {
260 }
261 }
262
263 protected override void ClearItems()
264 {
267 {
268 foreach (T item in base.Items)
269 {
271 }
272 }
273 base.ClearItems();
275 }
276
277 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "BindingList ctor is marked with RequiresUnreferencedCode.")]
278 protected override void InsertItem(int index, T item)
279 {
281 base.InsertItem(index, item);
283 {
285 }
287 }
288
289 protected override void RemoveItem(int index)
290 {
291 if (!allowRemove && (addNewPos < 0 || addNewPos != index))
292 {
293 throw new NotSupportedException();
294 }
297 {
299 }
300 base.RemoveItem(index);
302 }
303
304 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "BindingList ctor is marked with RequiresUnreferencedCode.")]
305 protected override void SetItem(int index, T item)
306 {
308 {
310 }
311 base.SetItem(index, item);
313 {
315 }
317 }
318
319 public virtual void CancelNew(int itemIndex)
320 {
321 if (addNewPos >= 0 && addNewPos == itemIndex)
322 {
324 addNewPos = -1;
325 }
326 }
327
328 public virtual void EndNew(int itemIndex)
329 {
330 if (addNewPos >= 0 && addNewPos == itemIndex)
331 {
332 addNewPos = -1;
333 }
334 }
335
336 public T AddNew()
337 {
338 return (T)((IBindingList)this).AddNew();
339 }
340
342 {
343 object obj = AddNewCore();
344 addNewPos = ((obj != null) ? IndexOf((T)obj) : (-1));
345 return obj;
346 }
347
348 protected virtual object? AddNewCore()
349 {
350 object obj = FireAddingNew();
351 if (obj == null)
352 {
354 }
355 Add((T)obj);
356 return obj;
357 }
358
360 {
361 ApplySortCore(prop, direction);
362 }
363
364 protected virtual void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
365 {
366 throw new NotSupportedException();
367 }
368
370 {
372 }
373
374 protected virtual void RemoveSortCore()
375 {
376 throw new NotSupportedException();
377 }
378
380 {
381 return FindCore(prop, key);
382 }
383
384 protected virtual int FindCore(PropertyDescriptor prop, object key)
385 {
386 throw new NotSupportedException();
387 }
388
392
396
397 [RequiresUnreferencedCode("Raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
398 private void HookPropertyChanged(T item)
399 {
401 {
403 {
405 }
406 notifyPropertyChanged.PropertyChanged += _propertyChangedEventHandler;
407 }
408 }
409
411 {
413 {
414 notifyPropertyChanged.PropertyChanged -= _propertyChangedEventHandler;
415 }
416 }
417
418 [RequiresUnreferencedCode("Raises ListChanged events with PropertyDescriptors. PropertyDescriptors require unreferenced code.")]
419 private void Child_PropertyChanged(object sender, PropertyChangedEventArgs e)
420 {
422 {
423 return;
424 }
425 if (sender == null || e == null || string.IsNullOrEmpty(e.PropertyName))
426 {
428 return;
429 }
430 T val;
431 try
432 {
433 val = (T)sender;
434 }
436 {
438 return;
439 }
440 int num = _lastChangeIndex;
441 if (num < 0 || num >= base.Count || !base[num].Equals(val))
442 {
443 num = (_lastChangeIndex = IndexOf(val));
444 }
445 if (num == -1)
446 {
449 return;
450 }
451 if (_itemTypeProperties == null)
452 {
454 }
458 }
459}
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
virtual ListSortDirection SortDirectionCore
PropertyDescriptorCollection _itemTypeProperties
AddingNewEventHandler AddingNew
virtual void CancelNew(int itemIndex)
virtual void EndNew(int itemIndex)
ListChangedEventHandler ListChanged
override void RemoveItem(int index)
virtual void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
override void SetItem(int index, T item)
virtual ? PropertyDescriptor SortPropertyCore
virtual int FindCore(PropertyDescriptor prop, object key)
void FireListChanged(ListChangedType type, int index)
AddingNewEventHandler _onAddingNew
PropertyChangedEventHandler _propertyChangedEventHandler
virtual void OnListChanged(ListChangedEventArgs e)
ListChangedEventHandler _onListChanged
void Child_PropertyChanged(object sender, PropertyChangedEventArgs e)
override void InsertItem(int index, T item)
virtual void OnAddingNew(AddingNewEventArgs e)
virtual ? PropertyDescriptor Find(string name, bool ignoreCase)
static PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
static readonly Type[] EmptyTypes
Definition Type.cs:19
void AddIndex(PropertyDescriptor property)
void ApplySort(PropertyDescriptor property, ListSortDirection direction)
void RemoveIndex(PropertyDescriptor property)
int Find(PropertyDescriptor property, object key)
delegate void AddingNewEventHandler(object? sender, AddingNewEventArgs e)
delegate void ListChangedEventHandler(object? sender, ListChangedEventArgs e)