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.º 2
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>
        }