public void Constructor1()
        {
            CodeTypeReference ref1 = new CodeTypeReference(string.Empty);
            CodeTypeReference ref2 = new CodeTypeReference(string.Empty);

            CodeTypeReference[]         refs = new CodeTypeReference[] { ref1, ref2 };
            CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection(
                refs);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(ref1), "#2");
            Assert.AreEqual(1, coll.IndexOf(ref2), "#3");
        }
        public void Insert()
        {
            CodeTypeReference ref1 = new CodeTypeReference(string.Empty);
            CodeTypeReference ref2 = new CodeTypeReference(string.Empty);

            CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection();

            coll.Add(ref1);
            Assert.AreEqual(1, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(ref1), "#2");
            coll.Insert(0, ref2);
            Assert.AreEqual(2, coll.Count, "#3");
            Assert.AreEqual(1, coll.IndexOf(ref1), "#4");
            Assert.AreEqual(0, coll.IndexOf(ref2), "#5");
        }
        public void Constructor2()
        {
            CodeTypeReference ref1 = new CodeTypeReference(string.Empty);
            CodeTypeReference ref2 = new CodeTypeReference(string.Empty);

            CodeTypeReferenceCollection c = new CodeTypeReferenceCollection();

            c.Add(ref1);
            c.Add(ref2);

            CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection(c);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(ref1), "#2");
            Assert.AreEqual(1, coll.IndexOf(ref2), "#3");
        }
        public void Remove()
        {
            CodeTypeReference ctr1 = new CodeTypeReference(string.Empty);
            CodeTypeReference ctr2 = new CodeTypeReference(string.Empty);

            CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection();

            coll.Add(ctr1);
            coll.Add(ctr2);
            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(ctr1), "#2");
            Assert.AreEqual(1, coll.IndexOf(ctr2), "#3");
            coll.Remove(ctr1);
            Assert.AreEqual(1, coll.Count, "#4");
            Assert.AreEqual(-1, coll.IndexOf(ctr1), "#5");
            Assert.AreEqual(0, coll.IndexOf(ctr2), "#6");
        }
        public void AddRange()
        {
            CodeTypeReference ref1 = new CodeTypeReference(string.Empty);
            CodeTypeReference ref2 = new CodeTypeReference(string.Empty);
            CodeTypeReference ref3 = new CodeTypeReference(string.Empty);

            CodeTypeReferenceCollection coll1 = new CodeTypeReferenceCollection();

            coll1.Add(ref1);
            coll1.Add(ref2);

            CodeTypeReferenceCollection coll2 = new CodeTypeReferenceCollection();

            coll2.Add(ref3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(ref1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(ref2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(ref3), "#4");

            CodeTypeReferenceCollection coll3 = new CodeTypeReferenceCollection();

            coll3.Add(ref3);
            coll3.AddRange(new CodeTypeReference[] { ref1, ref2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(ref1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(ref2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(ref3), "#8");
        }
        public void Constructor1_Deny_Unrestricted()
        {
            CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection(array);

            coll.CopyTo(array, 0);
            Assert.AreEqual(1, coll.Add(ctr), "Add");
            Assert.AreSame(ctr, coll[0], "this[int]");
            coll.AddRange(array);
            coll.AddRange(coll);
            Assert.IsTrue(coll.Contains(ctr), "Contains");
            Assert.AreEqual(0, coll.IndexOf(ctr), "IndexOf");
            coll.Insert(0, ctr);
            coll.Remove(ctr);
        }
Exemple #7
0
        // CodeTypeReferenceCollection
        public void CodeTypeReferenceCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeTypeReferenceCollection.
            CodeTypeReferenceCollection collection = new CodeTypeReferenceCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeTypeReference to the collection.
            collection.Add(new CodeTypeReference(typeof(bool)));
            //</Snippet3>

            //<Snippet4>
            // Adds an array of CodeTypeReference objects to the collection.
            CodeTypeReference[] references = { new CodeTypeReference(typeof(bool)), new CodeTypeReference(typeof(bool)) };
            collection.AddRange(references);

            // Adds a collection of CodeTypeReference objects to the collection.
            CodeTypeReferenceCollection referencesCollection = new CodeTypeReferenceCollection();

            referencesCollection.Add(new CodeTypeReference(typeof(bool)));
            referencesCollection.Add(new CodeTypeReference(typeof(bool)));
            collection.AddRange(referencesCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a CodeTypeReference in the
            // collection, and retrieves its index if it is found.
            CodeTypeReference testReference = new CodeTypeReference(typeof(bool));
            int itemIndex = -1;

            if (collection.Contains(testReference))
            {
                itemIndex = collection.IndexOf(testReference);
            }
            //</Snippet5>

            //<Snippet6>
            // Copies the contents of the collection, beginning at index 0,
            // to the specified CodeTypeReference array.
            // 'references' is a CodeTypeReference array.
            collection.CopyTo(references, 0);
            //</Snippet6>

            //<Snippet7>
            // Retrieves the count of the items in the collection.
            int collectionCount = collection.Count;

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeTypeReference at index 0 of the collection.
            collection.Insert(0, new CodeTypeReference(typeof(bool)));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeTypeReference from the collection.
            CodeTypeReference reference = new CodeTypeReference(typeof(bool));

            collection.Remove(reference);
            //</Snippet9>

            //<Snippet10>
            // Removes the CodeTypeReference at index 0.
            collection.RemoveAt(0);
            //</Snippet10>
            //</Snippet1>
        }