public void Constructor1_Deny_Unrestricted()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection(array);

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

            //</Snippet2>

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

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

            // Adds a collection of CodeCatchClause objects to the collection.
            CodeCatchClauseCollection clausesCollection = new CodeCatchClauseCollection();

            clausesCollection.Add(new CodeCatchClause("e", new CodeTypeReference(typeof(System.ArgumentOutOfRangeException))));
            clausesCollection.Add(new CodeCatchClause("e"));
            collection.AddRange(clausesCollection);
            //</Snippet4>

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

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

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

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

            //</Snippet7>

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

            //<Snippet9>
            // Removes the specified CodeCatchClause from the collection.
            CodeCatchClause clause = new CodeCatchClause("e");

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

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