public virtual void TestIterator() { IdentitySet4 set = new IdentitySet4(); object o1 = new object(); object o2 = new object(); set.Add(o1); set.Add(o2); Iterator4Assert.SameContent(Iterators.Iterate(new object[] { o1, o2 }), set.GetEnumerator ()); }
public void Add(object @object) { if (Contains(@object)) { return; } _modified.Add(@object); }
public virtual void Register(IListener4 listener) { if (_listeners == null) { _listeners = new IdentitySet4(); } _listeners.Add(listener); }
private static string DumpPreventRecursion(object obj, IdentitySet4 dumped, int stackLimit ) { stackLimit--; if (obj == null) { return("null"); } var clazz = obj.GetType(); if (Platform4.IsSimple(clazz)) { return(obj.ToString()); } var sb = new StringBuilder(); sb.Append(clazz.FullName); sb.Append(" ("); sb.Append(Runtime.IdentityHashCode(obj)); sb.Append(")"); if (dumped.Contains(obj) || stackLimit <= 0) { return(sb.ToString()); } dumped.Add(obj); var fields = Runtime.GetDeclaredFields(clazz); for (var fieldIndex = 0; fieldIndex < fields.Length; ++fieldIndex) { var field = fields[fieldIndex]; Platform4.SetAccessible(field); try { if (field.GetValue(null) == field.GetValue(obj)) { continue; } } catch (Exception) { } // static field.getModifiers() wouldn't sharpen sb.Append("\n"); sb.Append("\t"); sb.Append(field.Name); sb.Append(": "); try { sb.Append(DumpPreventRecursion(field.GetValue(obj), dumped, stackLimit)); } catch (Exception e) { sb.Append("Exception caught: "); sb.Append(e); } } return(sb.ToString()); }
public void Remove(object @object) { if (!Contains(@object)) { return; } _modified.Remove(@object); _removedAfterModified.Add(@object); }
public virtual void TestRemove() { IdentitySet4 set = new IdentitySet4(); object obj = new object(); set.Add(obj); Assert.IsTrue(set.Contains(obj)); set.Remove(obj); Assert.IsFalse(set.Contains(obj)); }
public virtual void Enlist(ITransactionParticipant participant) { if (null == participant) { throw new ArgumentNullException(); } CheckSynchronization(); if (!_participants.Contains(participant)) { _participants.Add(participant); } }
public virtual void TestByIdentity() { IdentitySet4 table = new IdentitySet4(2); IdentitySet4TestCase.Item item1 = new IdentitySet4TestCase.Item(1); Assert.IsFalse(table.Contains(item1)); table.Add(item1); Assert.IsTrue(table.Contains(item1)); IdentitySet4TestCase.Item item2 = new IdentitySet4TestCase.Item(2); Assert.IsFalse(table.Contains(item2)); table.Add(item2); Assert.IsTrue(table.Contains(item2)); Assert.AreEqual(2, table.Size()); int size = 0; IEnumerator i = table.GetEnumerator(); while (i.MoveNext()) { size++; } Assert.AreEqual(2, size); }
public bool Visit(object obj) { if (DirectionFrom().IsSecondClassObject(obj)) { return(false); } if (IsValueType(obj)) { return(true); } if (_objectsPreparedToReplicate.Contains(obj)) { return(false); } _objectsPreparedToReplicate.Add(obj); return(PrepareObjectToBeReplicated(obj, null, null)); }