Beispiel #1
0
        public void Constructor1_Deny_Unrestricted()
        {
            CodeNamespaceCollection coll = new CodeNamespaceCollection(array);

            coll.CopyTo(array, 0);
            Assert.AreEqual(1, coll.Add(cn), "Add");
            Assert.AreSame(cn, coll[0], "this[int]");
            coll.AddRange(array);
            coll.AddRange(coll);
            Assert.IsTrue(coll.Contains(cn), "Contains");
            Assert.AreEqual(0, coll.IndexOf(cn), "IndexOf");
            coll.Insert(0, cn);
            coll.Remove(cn);
        }
Beispiel #2
0
        public void Remove()
        {
            CodeNamespace cns1 = new CodeNamespace();
            CodeNamespace cns2 = new CodeNamespace();

            CodeNamespaceCollection coll = new CodeNamespaceCollection();

            coll.Add(cns1);
            coll.Add(cns2);
            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cns1), "#2");
            Assert.AreEqual(1, coll.IndexOf(cns2), "#3");
            coll.Remove(cns1);
            Assert.AreEqual(1, coll.Count, "#4");
            Assert.AreEqual(-1, coll.IndexOf(cns1), "#5");
            Assert.AreEqual(0, coll.IndexOf(cns2), "#6");
        }
Beispiel #3
0
        public void Remove_Null()
        {
            CodeNamespaceCollection coll = new CodeNamespaceCollection();

            coll.Remove((CodeNamespace)null);
        }
Beispiel #4
0
        public void Remove_NotInCollection()
        {
            CodeNamespaceCollection coll = new CodeNamespaceCollection();

            coll.Remove(new CodeNamespace());
        }
Beispiel #5
0
        // CodeNamespaceCollection
        public void CodeNamespaceCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeNamespaceCollection.
            CodeNamespaceCollection collection = new CodeNamespaceCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeNamespace to the collection.
            collection.Add(new CodeNamespace("TestNamespace"));
            //</Snippet3>

            //<Snippet4>
            // Adds an array of CodeNamespace objects to the collection.
            CodeNamespace[] namespaces = { new CodeNamespace("TestNamespace1"), new CodeNamespace("TestNamespace2") };
            collection.AddRange(namespaces);

            // Adds a collection of CodeNamespace objects to the collection.
            CodeNamespaceCollection namespacesCollection = new CodeNamespaceCollection();

            namespacesCollection.Add(new CodeNamespace("TestNamespace1"));
            namespacesCollection.Add(new CodeNamespace("TestNamespace2"));
            collection.AddRange(namespacesCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a CodeNamespace in the collection,
            // and retrieves its index if it is found.
            CodeNamespace testNamespace = new CodeNamespace("TestNamespace");
            int           itemIndex     = -1;

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

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

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

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeNamespace at index 0 of the collection.
            collection.Insert(0, new CodeNamespace("TestNamespace"));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeNamespace from the collection.
            CodeNamespace namespace_ = new CodeNamespace("TestNamespace");

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

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