[This is preliminary documentation and subject to change.]
Gets or sets the maximum number of item this collection can contain.
If the Add operation would get over the limit, the first item in the collection is discarded before the new item is added to the end of the collection.
| Exception Type | Condition |
|---|---|
| ArgumentException | An attempt was made to set the property to a negative value. |
The following code demostrates the effects of setting the Limit property to one.
[Visual Basic]
Imports System
Imports System.Diagnostics
Imports LaMarvin.ComponentModel
Public Class UndoItemCollectionLimit
Public Shared Sub Main()
' Create the collection.
Dim managers As UndoItemCollection = New UndoItemCollection
Debug.Assert(UndoEngine.DefaultUndoLimit = managers.Limit)
' Set the limit to one - only the last item will be kept in the collection.
managers.Limit = 1
' Add an IUndoItem-compatible item.
managers.Add(New PropertyChangeUndoManager)
Debug.Assert(managers.Count = 1)
' newManager replaces the previous one.
Dim NewManager As PropertyChangeUndoManager = New PropertyChangeUndoManager
managers.Add(NewManager)
Debug.Assert(managers.Count = 1)
Debug.Assert(NewManager.Equals(managers.Last))
Debug.Assert(NewManager.Equals(managers(0)))
End Sub
End Class
[C#]
using System;
using System.Diagnostics;
using LaMarvin.ComponentModel;
public sealed class UndoItemCollectionLimit
{
public static void Main()
{
// Create the collection.
UndoItemCollection managers = new UndoItemCollection();
Debug.Assert(UndoEngine.DefaultUndoLimit == managers.Limit);
// Set the limit to one - only the last item will be kept in the collection.
managers.Limit = 1;
// Add an IUndoItem-compatible item.
managers.Add(new PropertyChangeUndoManager());
Debug.Assert(managers.Count == 1);
// newManager replaces the previous one.
PropertyChangeUndoManager newManager = new PropertyChangeUndoManager();
managers.Add(newManager);
Debug.Assert(managers.Count == 1);
Debug.Assert(newManager == managers.Last);
Debug.Assert(newManager == managers[0]);
}
}
UndoItemCollection Class | LaMarvin.ComponentModel Namespace