CSharpTest.Net
ItemAdded Event
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > LurchTable<TKey,TValue> Class : ItemAdded Event

Glossary Item Box

Event raised after an item is added to the collection

Syntax

Visual Basic (Declaration) 
Public Event ItemAdded As Action(Of KeyValuePair(Of TKey,TValue))
C# 
public event Action<KeyValuePair<TKey,TValue>> ItemAdded

Example

Library/Library.Test/TestLurchTable.cs

C#Copy Code
var recorder = new RecordEvents<int, string>();
var test = new LurchTable<int, string>(LurchTableOrder.Access, 3, 1103, 10, 10, EqualityComparer<int>.Default);
test.ItemAdded += recorder.ItemAdded;
test.ItemUpdated += recorder.ItemUpdated;
test.ItemRemoved += recorder.ItemRemoved;
test[1] = "a";
Assert.AreEqual("a", recorder.LastAdded.Value);
test[2] = "b";
Assert.AreEqual("b", recorder.LastAdded.Value);
test[3] = "c";
Assert.AreEqual("c", recorder.LastAdded.Value);
Assert.AreEqual(3, test.Count);
Assert.AreEqual("b", test[2]); //access moves to front..
test[4] = "d";
Assert.AreEqual("d", recorder.LastAdded.Value);
Assert.AreEqual("a", recorder.LastRemove.Value);
test[5] = "e";
Assert.AreEqual("e", recorder.LastAdded.Value);
Assert.AreEqual("c", recorder.LastRemove.Value);
test[2] = "B";
Assert.AreEqual("B", recorder.LastUpdate.Value);
test[6] = "f";
Assert.AreEqual("f", recorder.LastAdded.Value);
Assert.AreEqual("d", recorder.LastRemove.Value);

Assert.AreEqual(3, test.Count); // still 3 items
string value;
Assert.IsTrue(test.TryRemove(5, out value));
Assert.AreEqual("e", value);
Assert.AreEqual("e", recorder.LastRemove.Value);

Assert.AreEqual("B", test.Dequeue().Value);
Assert.AreEqual("f", test.Dequeue().Value);
Assert.AreEqual(0, test.Count);
VB.NETCopy Code
Dim recorder As var = New RecordEvents(Of Integer, String)()
Dim test As var = New LurchTable(Of Integer, String)(LurchTableOrder.Access, 3, 1103, 10, 10, EqualityComparer(Of Integer).[Default])
test.ItemAdded += recorder.ItemAdded
test.ItemUpdated += recorder.ItemUpdated
test.ItemRemoved += recorder.ItemRemoved
test(1) = "a"
Assert.AreEqual("a", recorder.LastAdded.Value)
test(2) = "b"
Assert.AreEqual("b", recorder.LastAdded.Value)
test(3) = "c"
Assert.AreEqual("c", recorder.LastAdded.Value)
Assert.AreEqual(3, test.Count)
Assert.AreEqual("b", test(2))
'access moves to front..
test(4) = "d"
Assert.AreEqual("d", recorder.LastAdded.Value)
Assert.AreEqual("a", recorder.LastRemove.Value)
test(5) = "e"
Assert.AreEqual("e", recorder.LastAdded.Value)
Assert.AreEqual("c", recorder.LastRemove.Value)
test(2) = "B"
Assert.AreEqual("B", recorder.LastUpdate.Value)
test(6) = "f"
Assert.AreEqual("f", recorder.LastAdded.Value)
Assert.AreEqual("d", recorder.LastRemove.Value)

Assert.AreEqual(3, test.Count)
' still 3 items
Dim value As String
Assert.IsTrue(test.TryRemove(5, value))
Assert.AreEqual("e", value)
Assert.AreEqual("e", recorder.LastRemove.Value)

Assert.AreEqual("B", test.Dequeue().Value)
Assert.AreEqual("f", test.Dequeue().Value)
Assert.AreEqual(0, test.Count)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys