Inheritance: IEnumerator
Beispiel #1
0
 public void testIterator()
 {
     IEnumerator<Object> mock = new EmptyEnumerator<Object>();
     Assert.IsFalse(mock.MoveNext());
     try
     {
         mock.MoveNext();
         Assert.Fail("Should have thrown InvalidOperationException");
     }
     catch (System.InvalidOperationException)
     {
         // good
     }
 }
 private void IsEnumeratorEmpty(bool empty, [Optional] IEnumerator <History> enumerator)
 {
     if (empty)
     {
         enumerator              = new EmptyEnumerator <History>();
         EmptyState.IsVisible    = true;
         ListViewItems.IsVisible = false;
     }
     else
     {
         EmptyState.IsVisible    = false;
         ListViewItems.IsVisible = true;
     }
 }
Beispiel #3
0
        public void testIterator()
        {
            IEnumerator <Object> mock = new EmptyEnumerator <Object>();

            Assert.IsFalse(mock.MoveNext());
            try
            {
                mock.MoveNext();
                Assert.Fail("Should have thrown InvalidOperationException");
            }
            catch (System.InvalidOperationException)
            {
                // good
            }
        }
Beispiel #4
0
    public static void Main()
    {
        var sw = new Stopwatch();

        sw.Start();
        for (int i = 0; i < Iterations; i++)
        {
            IEnumerator enumerator = YieldBreak();
            while (enumerator.MoveNext())
            {
                throw new InvalidOperationException("Should not occur");
            }
        }
        sw.Stop();

        Console.WriteLine("Yield break: {0}", sw.Elapsed);

        GC.Collect();

        sw.Restart();
        for (int i = 0; i < Iterations; i++)
        {
            IEnumerator enumerator = Enumerable.Empty <object>().GetEnumerator();
            while (enumerator.MoveNext())
            {
                throw new InvalidOperationException("Should not occur");
            }
        }
        sw.Stop();

        Console.WriteLine("Enumerable.Empty<T>(): {0}", sw.Elapsed);

        GC.Collect();

        sw.Restart();
        var instance = new EmptyEnumerator();

        for (int i = 0; i < Iterations; i++)
        {
            while (instance.MoveNext())
            {
                throw new InvalidOperationException("Should not occur");
            }
        }
        sw.Stop();

        Console.WriteLine("EmptyEnumerator instance: {0}", sw.Elapsed);
    }
Beispiel #5
0
        /// <summary>
        /// Gets objects in a radius around a point
        /// </summary>
        /// <param name="type">OBJECT_TYPE (0=item, 1=npc, 2=player)</param>
        /// <param name="x">origin X</param>
        /// <param name="y">origin Y</param>
        /// <param name="z">origin Z</param>
        /// <param name="radius">radius around origin</param>
        /// <param name="withDistance">Get an ObjectDistance enumerator</param>
        /// <returns>IEnumerable to be used with foreach</returns>
        protected IEnumerable GetInRadius(Zone.eGameObjectType type, int x, int y, int z, ushort radius, bool withDistance, bool ignoreZ)
        {
            // check if we are around borders of a zone
            Zone startingZone = GetZone(x, y);

            if (startingZone != null)
            {
                ArrayList res = startingZone.GetObjectsInRadius(type, x, y, z, radius, new ArrayList(), ignoreZ);

                uint sqRadius = (uint)radius * radius;

                foreach (var currentZone in m_zones)
                {
                    if ((currentZone != startingZone)
                        && (currentZone.TotalNumberOfObjects > 0)
                        && CheckShortestDistance(currentZone, x, y, sqRadius))
                    {
                        res = currentZone.GetObjectsInRadius(type, x, y, z, radius, res, ignoreZ);
                    }
                }

                //Return required enumerator
                IEnumerable tmp = null;
                if (withDistance)
                {
                    switch (type)
                    {
                        case Zone.eGameObjectType.ITEM:
                            tmp = new ItemDistanceEnumerator(x, y, z, res);
                            break;
                        case Zone.eGameObjectType.NPC:
                            tmp = new NPCDistanceEnumerator(x, y, z, res);
                            break;
                        case Zone.eGameObjectType.PLAYER:
                            tmp = new PlayerDistanceEnumerator(x, y, z, res);
                            break;
                        case Zone.eGameObjectType.DOOR:
                            tmp = new DoorDistanceEnumerator(x, y, z, res);
                            break;
                        default:
                            tmp = new EmptyEnumerator();
                            break;
                    }
                }
                else
                {
                    tmp = new ObjectEnumerator(res);
                }
                return tmp;
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Error("GetInRadius starting zone is null for (" + type + ", " + x + ", " + y + ", " + z + ", " + radius + ") in Region ID=" + ID);
                }
                return new EmptyEnumerator();
            }
        }
Beispiel #6
0
 public EmptyEnumeratorShould()
 {
     _enumerator = EmptyEnumerator <int> .Instance;
 }