1: /*
2: Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>
3:
4: Permission is hereby granted, free of charge, to any person obtaining a copy
5: of this software and associated documentation files (the "Software"), to deal
6: in the Software without restriction, including without limitation the rights
7: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8: copies of the Software, and to permit persons to whom the Software is
9: furnished to do so, subject to the following conditions:
10:
11: The above copyright notice and this permission notice shall be included in
12: all copies or substantial portions of the Software.
13:
14: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20: THE SOFTWARE.*/
21:
22: #region Usings
23: using System;
24: using Utilities.Events;
25: using Utilities.Events.EventArgs;
26: #endregion
27:
28: namespace Utilities.DataTypes
29: {
30: /// <summary>
31: /// Class designed to replace List. Contains events so that we can tell
32: /// when the list has been changed.
33: /// </summary>
34: public class List<T> : System.Collections.Generic.List<T>
35: {
36: #region Events
37: public EventHandler<ChangedEventArgs> Changed;
38: #endregion
39:
40: #region Public Functions
41:
42: public new void Add(T value)
43: {
44: base.Add(value);
45: ChangedEventArgs TempArgs = new ChangedEventArgs();
46: TempArgs.Content = PropertyName;
47: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
48: }
49:
50: public new void AddRange(System.Collections.Generic.IEnumerable<T> value)
51: {
52: base.AddRange(value);
53: ChangedEventArgs TempArgs = new ChangedEventArgs();
54: TempArgs.Content = PropertyName;
55: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
56: }
57:
58: public new bool Remove(T obj)
59: {
60: bool ReturnValue = base.Remove(obj);
61: ChangedEventArgs TempArgs = new ChangedEventArgs();
62: TempArgs.Content = PropertyName;
63: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
64: return ReturnValue;
65: }
66:
67: public new void RemoveAt(int index)
68: {
69: base.RemoveAt(index);
70: ChangedEventArgs TempArgs = new ChangedEventArgs();
71: TempArgs.Content = PropertyName;
72: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
73: }
74:
75: public new int RemoveAll(Predicate<T> match)
76: {
77: int ReturnValue = base.RemoveAll(match);
78: ChangedEventArgs TempArgs = new ChangedEventArgs();
79: TempArgs.Content = PropertyName;
80: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
81: return ReturnValue;
82: }
83:
84: public new void RemoveRange(int index, int count)
85: {
86: base.RemoveRange(index, count);
87: ChangedEventArgs TempArgs = new ChangedEventArgs();
88: TempArgs.Content = PropertyName;
89: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
90: }
91:
92: public new void Insert(int index, T value)
93: {
94: base.Insert(index, value);
95: ChangedEventArgs TempArgs = new ChangedEventArgs();
96: TempArgs.Content = PropertyName;
97: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
98: }
99:
100: public new void InsertRange(int index, System.Collections.Generic.IEnumerable<T> collection)
101: {
102: base.InsertRange(index, collection);
103: ChangedEventArgs TempArgs = new ChangedEventArgs();
104: TempArgs.Content = PropertyName;
105: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
106: }
107:
108: public new void Clear()
109: {
110: base.Clear();
111: ChangedEventArgs TempArgs = new ChangedEventArgs();
112: TempArgs.Content = PropertyName;
113: EventHelper.Raise<ChangedEventArgs>(Changed, this, TempArgs);
114: }
115:
116: #endregion
117:
118: #region Properties
119:
120: public new T this[int index]
121: {
122: get { return base[index]; }
123: set
124: {
125: base[index] = value;
126: EventHelper.Raise<ChangedEventArgs>(Changed, this, new ChangedEventArgs());
127: }
128: }
129:
130: public string PropertyName { get; set; }
131:
132: #endregion
133: }
134: }