Exemple #1
0
 public virtual void Register(IListener4 listener)
 {
     if (_listeners == null)
     {
         _listeners = new IdentitySet4();
     }
     _listeners.Add(listener);
 }
		public virtual void Register(IListener4 listener)
		{
			if (_listeners == null)
			{
				_listeners = new IdentitySet4();
			}
			_listeners.Add(listener);
		}
		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 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 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);
		}
Exemple #6
0
		private static string DumpPreventRecursion(object obj, IdentitySet4 dumped, int stackLimit
			)
		{
			stackLimit--;
			if (obj == null)
			{
				return "null";
			}
			Type clazz = obj.GetType();
			if (Platform4.IsSimple(clazz))
			{
				return obj.ToString();
			}
			StringBuilder 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);
			FieldInfo[] fields = Sharpen.Runtime.GetDeclaredFields(clazz);
			for (int fieldIndex = 0; fieldIndex < fields.Length; ++fieldIndex)
			{
				FieldInfo 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();
		}