public void AddRange()
        {
            CodeTypeDeclaration td1 = new CodeTypeDeclaration();
            CodeTypeDeclaration td2 = new CodeTypeDeclaration();
            CodeTypeDeclaration td3 = new CodeTypeDeclaration();

            CodeTypeDeclarationCollection coll1 = new CodeTypeDeclarationCollection();

            coll1.Add(td1);
            coll1.Add(td2);

            CodeTypeDeclarationCollection coll2 = new CodeTypeDeclarationCollection();

            coll2.Add(td3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(td1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(td2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(td3), "#4");

            CodeTypeDeclarationCollection coll3 = new CodeTypeDeclarationCollection();

            coll3.Add(td3);
            coll3.AddRange(new CodeTypeDeclaration[] { td1, td2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(td1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(td2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(td3), "#8");
        }
        public void Constructor1_Deny_Unrestricted()
        {
            CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(array);

            coll.CopyTo(array, 0);
            Assert.AreEqual(1, coll.Add(ctd), "Add");
            Assert.AreSame(ctd, coll[0], "this[int]");
            coll.AddRange(array);
            coll.AddRange(coll);
            Assert.IsTrue(coll.Contains(ctd), "Contains");
            Assert.AreEqual(0, coll.IndexOf(ctd), "IndexOf");
            coll.Insert(0, ctd);
            coll.Remove(ctd);
        }
Exemplo n.º 3
0
        // CodeTypeDeclarationCollection
        public void CodeTypeDeclarationCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeTypeDeclarationCollection.
            CodeTypeDeclarationCollection collection = new CodeTypeDeclarationCollection();

            //</Snippet2>

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

            //<Snippet4>
            // Adds an array of CodeTypeDeclaration objects to the collection.
            CodeTypeDeclaration[] declarations = { new CodeTypeDeclaration("TestType1"), new CodeTypeDeclaration("TestType2") };
            collection.AddRange(declarations);

            // Adds a collection of CodeTypeDeclaration objects to the
            // collection.
            CodeTypeDeclarationCollection declarationsCollection = new CodeTypeDeclarationCollection();

            declarationsCollection.Add(new CodeTypeDeclaration("TestType1"));
            declarationsCollection.Add(new CodeTypeDeclaration("TestType2"));
            collection.AddRange(declarationsCollection);
            //</Snippet4>

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

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

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

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

            //</Snippet7>

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

            //<Snippet9>
            // Removes the specified CodeTypeDeclaration from the collection.
            CodeTypeDeclaration declaration = new CodeTypeDeclaration("TestType");

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

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