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);
        }
        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 Remove_Null()
        {
            CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection();

            coll.Remove((CodeTypeReference)null);
        }
        public void Remove_NotInCollection()
        {
            CodeTypeReferenceCollection coll = new CodeTypeReferenceCollection();

            coll.Remove(new CodeTypeReference(string.Empty));
        }
Ejemplo n.º 5
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>
        }