Esempio n. 1
0
        public void RemoveWindow(Window window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }
            int index = windows.IndexOf(window);

            if (index == -1)
            {
                return;
            }

            windows.RemoveAt(index);
        }
Esempio n. 2
0
        //public
        public static T GetService <T>()
        {
            Type    type   = typeof(T);
            dynamic result = null;

            if (!initializedServices.TryGetValue(type, out result))
            {
                int index = services.IndexOf(type);
                if (index > -1)
                {
                    result = initializeService(type);
                    initializedServices.TryAdd(type, result);
                }
            }

            if (result == null)
            {
                lookupCache.TryGetValue(type, out result);
            }

            if (result == null)
            {
                for (int i = 0; i < services.Count; i++)
                {
                    Type t = services[i];
                    if (ReflectUtil.DoesExtend(type, t))
                    {
                        initializedServices.TryGetValue(t, out result);
                        if (result == null)
                        {
                            result = initializeService(t);
                            initializedServices.TryAdd(t, result);
                        }
                        lookupCache.TryAdd(type, result);
                        break;
                    }
                }
            }

            if (result == null)
            {
                return(default(T));
            }
            else
            {
                return((T)result);
            }
        }
Esempio n. 3
0
        internal static void RemoveWindow(Window window)
        {
            int index = windows.IndexOf(window);

            if (index == -1)
            {
                return;
            }
            windows.RemoveAt(index);
        }
Esempio n. 4
0
        public void RemoveWindow(Display.Window window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            int index = windows.IndexOf(window);

            if (index == -1)
            {
                return;
            }

            windows.RemoveAt(index);
            window.GainedFocus         -= onFocused;
            window.KeyPressed          -= onKeyDown;
            window.KeyReleased         -= onKeyUp;
            window.MouseMoved          -= onMouseMove;
            window.MouseWheelScrolled  -= onMouseWheel;
            window.MouseButtonPressed  -= onMouseDown;
            window.MouseButtonReleased -= onMouseUp;
        }
Esempio n. 5
0
 public int IndexOf(ListItem item)
 {
     return(_backingList.IndexOf(item));
 }
    // This Unit test is based from full framework test
    public static void SynchronizedCollectionPublicMembersTest()
    {
        SynchronizedCollection <int> coll = new SynchronizedCollection <int>();
        int size = 100;

        for (int i = 0; i < size; i++)
        {
            coll.Add(i);
        }

        Assert.True(coll.Count == size, string.Format("collection count was wrong! Expected: {0} got: {1}", size, coll.Count));

        for (int i = 0; i < size; i++)
        {
            Assert.True(coll[i] == i, string.Format("coll element {0} was wrong! Expected: {1} got: {2} ", i, i, coll[i]));
            Assert.True(coll.IndexOf(i) == i, string.Format("coll IndexOf wasn't right! Expected: {0} got: {1}", i, coll.IndexOf(i)));
            Assert.True(coll.Contains(i), string.Format("coll Contains failed to find the value {0}.", i));
        }

        SynchronizedCollection <int> coll2 = new SynchronizedCollection <int>(new object(), new List <int>(coll));

        for (int i = 0; i < size; i++)
        {
            Assert.True(coll2[i] == i, string.Format("coll2 element was wrong! expected: {0} got: {1} ", i, coll2[i]));
        }

        SynchronizedCollection <int> coll3 = new SynchronizedCollection <int>(new object(), 1, 2, 3, 4, 5, 6);

        for (int i = 0; i < 5; i++)
        {
            Assert.True(coll3[i] == i + 1, string.Format("coll3 element {0} was wrong! expected: {1} got: {2}", i, i + 1, coll3[i]));
        }
        int newValue = 80;

        coll3[5] = newValue;
        Assert.True(coll3[5] == newValue);

        IEnumerator <int> e = coll.GetEnumerator();
        int n = 0;

        while (e.MoveNext())
        {
            Assert.True(e.Current.Equals(n++), string.Format("Expected: {0}, got:{1}", n - 1, e.Current));
        }

        Assert.True(n == 100, string.Format("Expect number of elements: {0}, got:{1}", 100, n));

        int[] array = new int[size + 1];
        coll.CopyTo(array, 1);
        for (int i = 0; i < size; i++)
        {
            Assert.True(array[i + 1] == i, string.Format("After CopyTo, Element {0} was wrong!  Expected: {1} got:  {2}", i, i + 1, array[i + 1]));
        }

        coll.Add(coll.Count);
        coll.Insert(0, -1);
        coll.RemoveAt(0);
        coll.Remove(coll.Count - 1);
        Assert.True(coll.Count == size, string.Format("Expect number of elements after modification: {0}, got: {1}", size, coll.Count));

        for (int i = 0; i < size; i++)
        {
            Assert.True(coll[i] == i, string.Format("coll element was wrong after modification! Expected: {0} got: {1} ", i, coll[i]));
        }

        coll.Clear();
        Assert.True(coll.Count == 0, string.Format("Clear operation failed!, expected: 0, actual {0}", coll.Count));

        // Negative cases
        Assert.Throws <ArgumentNullException>("syncRoot", () =>
        {
            new SynchronizedCollection <int>(null);
        });

        Assert.Throws <ArgumentNullException>("list", () =>
        {
            new SynchronizedCollection <int>(new object(), null);
        });

        Assert.Throws <ArgumentNullException>("syncRoot", () =>
        {
            new SynchronizedCollection <int>(null, new List <int>());
        });

        Assert.Throws <ArgumentNullException>("syncRoot", () =>
        {
            new SynchronizedCollection <int>(null, 1, 2, 3, 4);
        });

        Assert.Throws <ArgumentOutOfRangeException>(() =>
        {
            coll[1000] = 5;
        });

        Assert.Throws <ArgumentOutOfRangeException>(() =>
        {
            coll[-1] = 5;
        });

        Assert.Throws <ArgumentOutOfRangeException>(() =>
        {
            coll.Insert(1000, 5);
        });

        Assert.Throws <ArgumentOutOfRangeException>(() =>
        {
            coll.Insert(-1, 5);
        });

        Assert.False(coll.Remove(100000));

        Assert.Throws <ArgumentOutOfRangeException>(() =>
        {
            coll.RemoveAt(-1);
        });

        Assert.Throws <ArgumentOutOfRangeException>(() =>
        {
            coll.RemoveAt(10000);
        });
    }
Esempio n. 7
0
 /// <summary>
 /// Returns the index within the collection of the specified item
 /// </summary>
 /// <param name="value">An object representing the item to locate in the collection.</param>
 /// <returns>The zero-based index where the item is located within the collection; otherwise, negative one (-1). </returns>
 public int IndexOf(ListItem value)
 {
     // Find the 0 based index of the requested entry
     return(m_list.IndexOf(value));
 }
Esempio n. 8
0
    // This Unit test is based from full framework test
    public static void SynchronizedCollectionPublicMembersTest()
    {
        SynchronizedCollection<int> coll = new SynchronizedCollection<int>();
        int size = 100;
        for (int i = 0; i < size; i++)
            coll.Add(i);

        Assert.True(coll.Count == size, string.Format("collection count was wrong! Expected: {0} got: {1}", size, coll.Count));

        for (int i = 0; i < size; i++)
        {
            Assert.True(coll[i] == i, string.Format("coll element {0} was wrong! Expected: {1} got: {2} ", i, i, coll[i]));
            Assert.True(coll.IndexOf(i) == i, string.Format("coll IndexOf wasn't right! Expected: {0} got: {1}" , i, coll.IndexOf(i)));
            Assert.True(coll.Contains(i), string.Format("coll Contains failed to find the value {0}.", i));
        }

        SynchronizedCollection<int> coll2 = new SynchronizedCollection<int>(new object(), new List<int>(coll));
        for (int i = 0; i < size; i++)
        {
            Assert.True(coll2[i] == i, string.Format("coll2 element was wrong! expected: {0} got: {1} ", i, coll2[i]));
        }

        SynchronizedCollection<int> coll3 = new SynchronizedCollection<int>(new object(), 1, 2, 3, 4, 5 , 6);
        for (int i = 0; i < 5; i++)
        {
            Assert.True(coll3[i] == i + 1, string.Format("coll3 element {0} was wrong! expected: {1} got: {2}", i, i+1, coll3[i]));
        }
        int newValue = 80;
        coll3[5] = newValue;
        Assert.True(coll3[5] == newValue);

        IEnumerator <int> e = coll.GetEnumerator();
        int n = 0;
        while (e.MoveNext())
        {
            Assert.True(e.Current.Equals(n++), string.Format("Expected: {0}, got:{1}", n-1, e.Current));
        }

        Assert.True(n == 100, string.Format("Expect number of elements: {0}, got:{1}", 100, n));

        int[] array = new int[size + 1];
        coll.CopyTo(array, 1);
        for (int i = 0; i < size; i++)
        {
            Assert.True(array[i + 1] == i, string.Format("After CopyTo, Element {0} was wrong!  Expected: {1} got:  {2}", i, i+1, array[i + 1]));
        }

        coll.Add(coll.Count);
        coll.Insert(0, -1);
        coll.RemoveAt(0);
        coll.Remove(coll.Count - 1);
        Assert.True(coll.Count == size, string.Format("Expect number of elements after modification: {0}, got: {1}", size, coll.Count));

        for (int i = 0; i < size; i++)
        {
            Assert.True(coll[i] == i, string.Format("coll element was wrong after modification! Expected: {0} got: {1} ", i, coll[i]));
        }

        coll.Clear();
        Assert.True(coll.Count == 0, string.Format("Clear operation failed!, expected: 0, actual {0}", coll.Count));

        // Negative cases
        Assert.Throws<ArgumentNullException>("syncRoot", () =>
        {
            new SynchronizedCollection<int>(null);
        });

        Assert.Throws<ArgumentNullException>("list", () =>
        {
            new SynchronizedCollection<int>(new object(), null);
        });

        Assert.Throws<ArgumentNullException>("syncRoot", () =>
        {
            new SynchronizedCollection<int>(null, new List<int>());
        });

        Assert.Throws<ArgumentNullException>("syncRoot", () =>
        {
            new SynchronizedCollection<int>(null, 1, 2, 3, 4);
        });

        Assert.Throws<ArgumentOutOfRangeException>(() =>
        {
            coll[1000] = 5;
        });

        Assert.Throws<ArgumentOutOfRangeException>(() =>
        {
            coll[-1] = 5;
        });

        Assert.Throws<ArgumentOutOfRangeException>(() =>
        {
            coll.Insert(1000, 5);
        });

        Assert.Throws<ArgumentOutOfRangeException>(() =>
        {
            coll.Insert(-1, 5);
        });

        Assert.False(coll.Remove(100000));

        Assert.Throws<ArgumentOutOfRangeException>(() =>
        {
            coll.RemoveAt(-1);
        });

        Assert.Throws<ArgumentOutOfRangeException>(() =>
        {
            coll.RemoveAt(10000);
        });
    }