[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
// attributes
[Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
- public sealed class ListItemCollection : IList, ICollection, IEnumerable, IStateManager {
- #region Fields
- private ArrayList items;
- private bool tracking;
- private bool dirty;
+ public sealed class ListItemCollection : IList, ICollection, IEnumerable, IStateManager
+ {
+#region Fields
+ ArrayList items;
+ bool tracking;
+ bool dirty;
int lastDirty = 0;
- #endregion // Fields
+#endregion // Fields
- #region Public Constructors
+#region Public Constructors
public ListItemCollection() {
items = new ArrayList();
}
- #endregion // Public Constructors
+#endregion // Public Constructors
- #region Public Instance Properties
+#region Public Instance Properties
public int Capacity {
get {
return items.Capacity;
if (tracking)
SetDirty ();
}
- #endregion // Public Instance Methods
+#endregion // Public Instance Methods
- #region Interface methods
+#region Interface methods
bool IList.IsFixedSize {
get {
return items.IsFixedSize;
}
}
- void IStateManager.LoadViewState (object savedState) {
+ void IStateManager.LoadViewState (object savedState)
+ {
Pair pair = savedState as Pair;
if (pair == null)
return;
bool newCollection = (bool) pair.First;
object [] itemsArray = (object []) pair.Second;
- int count = itemsArray.Length;
+ int count = itemsArray==null ? 0 : itemsArray.Length;
if (newCollection)
- items = new ArrayList(count);
+ if (count > 0)
+ items = new ArrayList(count);
+ else
+ items = new ArrayList();
for (int i = 0; i < count; i++) {
ListItem item = new ListItem ();
if (newCollection) {
item.LoadViewState (itemsArray [i]);
+ item.SetDirty ();
Add (item);
}
else{
bool itemsDirty = false;
count = items.Count;
- if (count == 0)
+ if (count == 0 && !dirty)
return null;
- object [] itemsState = new object [count];
+ object [] itemsState = null;
+ if (count > 0)
+ itemsState = new object [count];
+
for (int i = 0; i < count; i++) {
itemsState [i] = ((IStateManager) items [i]).SaveViewState ();
if (itemsState [i] != null)
((ListItem)items[i]).TrackViewState();
}
}
- #endregion // Interface methods
+#endregion // Interface methods
- private void SetDirty ()
+ void SetDirty ()
{
dirty = true;
for (int i = lastDirty; i < items.Count; i++)
((ListItem) items [i]).SetDirty ();
-
- lastDirty = items.Count;
+
+ lastDirty = items.Count - 1;
+ if (lastDirty < 0)
+ lastDirty = 0;
}
}
}