Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
 public virtual void Enlist(ITransactionParticipant participant)
 {
     if (null == participant)
     {
         throw new ArgumentNullException();
     }
     CheckSynchronization();
     if (!_participants.Contains(participant))
     {
         _participants.Add(participant);
     }
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 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));
 }
Exemplo n.º 6
0
 private bool Contains(object @object)
 {
     return(_modified.Contains(@object));
 }