Visual Basic (Declaration) | |
---|---|
Public ReadOnly Property Lock As ILockStrategy |
C# | |
---|---|
public ILockStrategy Lock {get;} |
Library/Library.Test/TestSynchronizedCollections.cs
C# | Copy Code |
---|---|
LockCounterFactory<SimpleReadWriteLocking> factory = new LockCounterFactory<SimpleReadWriteLocking>(); ILockStrategy lck = factory.Create(); SynchronizedDictionary<int, string> test = new SynchronizedDictionary<int, string>(lck); Assert.IsTrue(ReferenceEquals(lck, test.Lock)); test.Add(42, "42"); Assert.AreEqual(1, factory.TotalWriterCount); Assert.AreEqual(0, factory.TotalReaderCount); test[42] = "51"; Assert.AreEqual(2, factory.TotalWriterCount); test.Add(1, "52"); Assert.AreEqual(3, factory.TotalWriterCount); test.Remove(-1); Assert.AreEqual(4, factory.TotalWriterCount); test.Remove(1); Assert.AreEqual(5, factory.TotalWriterCount); Assert.AreEqual("51", test[42]); Assert.AreEqual(1, factory.TotalReaderCount); foreach (KeyValuePair<int, string> i in test) GC.KeepAlive(i); Assert.AreEqual(2, factory.TotalReaderCount); Assert.AreEqual(false, test.ContainsKey(-1)); Assert.AreEqual(3, factory.TotalReaderCount); Assert.AreEqual(1, test.Count); Assert.AreEqual(4, factory.TotalReaderCount); string cmp; Assert.IsTrue(test.TryGetValue(42, out cmp) && cmp == "51"); Assert.AreEqual(5, factory.TotalReaderCount); |
VB.NET | Copy Code |
---|---|
Dim factory As New LockCounterFactory(Of SimpleReadWriteLocking)() Dim lck As ILockStrategy = factory.Create() Dim test As New SynchronizedDictionary(Of Integer, String)(lck) Assert.IsTrue(ReferenceEquals(lck, test.Lock)) test.Add(42, "42") Assert.AreEqual(1, factory.TotalWriterCount) Assert.AreEqual(0, factory.TotalReaderCount) test(42) = "51" Assert.AreEqual(2, factory.TotalWriterCount) test.Add(1, "52") Assert.AreEqual(3, factory.TotalWriterCount) test.Remove(-1) Assert.AreEqual(4, factory.TotalWriterCount) test.Remove(1) Assert.AreEqual(5, factory.TotalWriterCount) Assert.AreEqual("51", test(42)) Assert.AreEqual(1, factory.TotalReaderCount) For Each i As KeyValuePair(Of Integer, String) In test GC.KeepAlive(i) Next Assert.AreEqual(2, factory.TotalReaderCount) Assert.AreEqual(False, test.ContainsKey(-1)) Assert.AreEqual(3, factory.TotalReaderCount) Assert.AreEqual(1, test.Count) Assert.AreEqual(4, factory.TotalReaderCount) Dim cmp As String Assert.IsTrue(test.TryGetValue(42, cmp) AndAlso cmp = "51") Assert.AreEqual(5, factory.TotalReaderCount) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7