static CodeCatchClause[] _ToArray(CodeCatchClauseCollection ccs)
        {
            var result = new CodeCatchClause[ccs.Count];

            ccs.CopyTo(result, 0);
            return(result);
        }
        public void AddRange()
        {
            CodeCatchClause cc1 = new CodeCatchClause();
            CodeCatchClause cc2 = new CodeCatchClause();
            CodeCatchClause cc3 = new CodeCatchClause();

            CodeCatchClauseCollection coll1 = new CodeCatchClauseCollection();

            coll1.Add(cc1);
            coll1.Add(cc2);

            CodeCatchClauseCollection coll2 = new CodeCatchClauseCollection();

            coll2.Add(cc3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(cc1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(cc2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(cc3), "#4");

            CodeCatchClauseCollection coll3 = new CodeCatchClauseCollection();

            coll3.Add(cc3);
            coll3.AddRange(new CodeCatchClause[] { cc1, cc2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(cc1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(cc2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(cc3), "#8");
        }
        public void AddRange_Self()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            coll.Add(new CodeCatchClause());
            Assert.AreEqual(1, coll.Count, "#1");
            coll.AddRange(coll);
            Assert.AreEqual(2, coll.Count, "#2");
        }
        public void Constructor1_NullItem()
        {
            CodeCatchClause[] catchClauses = new CodeCatchClause[] {
                new CodeCatchClause(), null
            };

            CodeCatchClauseCollection coll = new CodeCatchClauseCollection(
                catchClauses);
        }
Exemple #5
0
        private void GenerateTryCatchFinallyStatement(CodeTryCatchFinallyStatement e)
        {
            output.Write("try");
            OutputStartingBrace();
            Indent++;
            GenerateStatements(e.TryStatements);
            Indent--;
            CodeCatchClauseCollection catches = e.CatchClauses;

            if (catches.Count > 0)
            {
                IEnumerator en = catches.GetEnumerator();
                while (en.MoveNext())
                {
                    output.Write("}");
                    if (options.ElseOnClosing)
                    {
                        output.Write(" ");
                    }
                    else
                    {
                        output.WriteLine("");
                    }
                    CodeCatchClause current = (CodeCatchClause)en.Current;
                    output.Write("catch (");
                    OutputType(current.CatchExceptionType);
                    output.Write(" ");
                    OutputIdentifier(current.LocalName);
                    output.Write(")");
                    OutputStartingBrace();
                    Indent++;
                    GenerateStatements(current.Statements);
                    Indent--;
                }
            }

            CodeStatementCollection finallyStatements = e.FinallyStatements;

            if (finallyStatements.Count > 0)
            {
                output.Write("}");
                if (options.ElseOnClosing)
                {
                    output.Write(" ");
                }
                else
                {
                    output.WriteLine("");
                }
                output.Write("finally");
                OutputStartingBrace();
                Indent++;
                GenerateStatements(finallyStatements);
                Indent--;
            }
            output.WriteLine("}");
        }
        public void Constructor0()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            Assert.IsFalse(((IList)coll).IsFixedSize, "#1");
            Assert.IsFalse(((IList)coll).IsReadOnly, "#2");
            Assert.AreEqual(0, coll.Count, "#3");
            Assert.IsFalse(((ICollection)coll).IsSynchronized, "#4");
            Assert.IsNotNull(((ICollection)coll).SyncRoot, "#5");
        }
 public static void ReplaceType(this CodeCatchClauseCollection collection, string oldType, string newType)
 {
     if (collection == null)
     {
         return;
     }
     foreach (CodeCatchClause clause in collection)
     {
         clause.ReplaceType(oldType, newType);
     }
 }
        public void Constructor1()
        {
            CodeCatchClause cc1 = new CodeCatchClause();
            CodeCatchClause cc2 = new CodeCatchClause();

            CodeCatchClause[]         catchClauses = new CodeCatchClause[] { cc1, cc2 };
            CodeCatchClauseCollection coll         = new CodeCatchClauseCollection(
                catchClauses);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cc1), "#2");
            Assert.AreEqual(1, coll.IndexOf(cc2), "#3");
        }
        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);
        }
        public static CodeCatchClauseCollection Clone(this CodeCatchClauseCollection collection)
        {
            if (collection == null)
            {
                return(null);
            }
            CodeCatchClauseCollection c = new CodeCatchClauseCollection();

            foreach (CodeCatchClause clause in collection)
            {
                c.Add(clause.Clone());
            }
            return(c);
        }
        public void Insert()
        {
            CodeCatchClause cc1 = new CodeCatchClause();
            CodeCatchClause cc2 = new CodeCatchClause();

            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            coll.Add(cc1);
            Assert.AreEqual(1, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cc1), "#2");
            coll.Insert(0, cc2);
            Assert.AreEqual(2, coll.Count, "#3");
            Assert.AreEqual(1, coll.IndexOf(cc1), "#4");
            Assert.AreEqual(0, coll.IndexOf(cc2), "#5");
        }
        public void Constructor2()
        {
            CodeCatchClause cc1 = new CodeCatchClause();
            CodeCatchClause cc2 = new CodeCatchClause();

            CodeCatchClauseCollection c = new CodeCatchClauseCollection();

            c.Add(cc1);
            c.Add(cc2);

            CodeCatchClauseCollection coll = new CodeCatchClauseCollection(c);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cc1), "#2");
            Assert.AreEqual(1, coll.IndexOf(cc2), "#3");
        }
Exemple #13
0
        protected override void GenerateTryCatchFinallyStatement
            (CodeTryCatchFinallyStatement e)
        {
            Output.Write("try");
            StartBlock();
            GenerateStatements(e.TryStatements);
            EndBlock();
            CodeCatchClauseCollection clauses = e.CatchClauses;

            if (clauses.Count > 0)
            {
                foreach (CodeCatchClause clause in clauses)
                {
                    if (clause.CatchExceptionType != null)
                    {
                        Output.Write("catch (");
                        OutputType(clause.CatchExceptionType);
                        if (clause.LocalName != null)
                        {
                            Output.Write(" ");
                            OutputIdentifier(clause.LocalName);
                        }
                        Output.Write(")");
                    }
                    else
                    {
                        Output.Write("catch");
                    }
                    StartBlock();
                    GenerateStatements(clause.Statements);
                    EndBlock();
                }
            }
            CodeStatementCollection fin = e.FinallyStatements;

            if (fin.Count > 0)
            {
                Output.Write("finally");
                StartBlock();
                GenerateStatements(fin);
                EndBlock();
            }
        }
Exemple #14
0
        protected override void GenerateTryCatchFinallyStatement
            (CodeTryCatchFinallyStatement e)
        {
            Output.WriteLine("Try");
            ++Indent;
            GenerateStatements(e.TryStatements);
            --Indent;
            CodeCatchClauseCollection clauses = e.CatchClauses;

            if (clauses.Count > 0)
            {
                foreach (CodeCatchClause clause in clauses)
                {
                    if (clause.CatchExceptionType != null)
                    {
                        Output.Write("Catch ");
                        OutputIdentifier(clause.LocalName);
                        Output.Write(" As ");
                        OutputType(clause.CatchExceptionType);
                        Output.WriteLine();
                    }
                    else
                    {
                        Output.WriteLine("Catch");
                    }
                    ++Indent;
                    GenerateStatements(clause.Statements);
                    --Indent;
                }
            }
            CodeStatementCollection fin = e.FinallyStatements;

            if (fin.Count > 0)
            {
                Output.WriteLine("Finally");
                ++Indent;
                GenerateStatements(fin);
                --Indent;
            }
            Output.WriteLine("End Try");
        }
Exemple #15
0
        private void ValidateTryCatchFinallyStatement(CodeTryCatchFinallyStatement e)
        {
            ValidateStatements(e.TryStatements);
            CodeCatchClauseCollection catches = e.CatchClauses;

            if (catches.Count > 0)
            {
                foreach (CodeCatchClause current in catches)
                {
                    ValidateTypeReference(current.CatchExceptionType);
                    ValidateIdentifier(current, nameof(current.LocalName), current.LocalName);
                    ValidateStatements(current.Statements);
                }
            }

            CodeStatementCollection finallyStatements = e.FinallyStatements;

            if (finallyStatements.Count > 0)
            {
                ValidateStatements(finallyStatements);
            }
        }
Exemple #16
0
        private void ValidateTryCatchFinallyStatement(CodeTryCatchFinallyStatement e)
        {
            this.ValidateStatements(e.TryStatements);
            CodeCatchClauseCollection catchClauses = e.CatchClauses;

            if (catchClauses.Count > 0)
            {
                IEnumerator enumerator = catchClauses.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CodeCatchClause current = (CodeCatchClause)enumerator.Current;
                    ValidateTypeReference(current.CatchExceptionType);
                    ValidateIdentifier(current, "LocalName", current.LocalName);
                    this.ValidateStatements(current.Statements);
                }
            }
            CodeStatementCollection finallyStatements = e.FinallyStatements;

            if (finallyStatements.Count > 0)
            {
                this.ValidateStatements(finallyStatements);
            }
        }
 public void AddRange(CodeCatchClauseCollection value)
 {
 }
 public void Constructor1_Null()
 {
     CodeCatchClauseCollection coll = new CodeCatchClauseCollection(
         (CodeCatchClause[])null);
 }
Exemple #19
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>
        }
	public CodeCatchClauseCollection(CodeCatchClauseCollection value) {}
	public void AddRange(CodeCatchClauseCollection value) {}
        public void Remove_Null()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            coll.Remove((CodeCatchClause)null);
        }
        public void Add_Null()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            coll.Add((CodeCatchClause)null);
        }
        public void Remove_NotInCollection()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            coll.Remove(new CodeCatchClause());
        }
 public CodeCatchClauseCollection(CodeCatchClauseCollection value)
 {
 }
        public void AddRange_Null_Collection()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            coll.AddRange((CodeCatchClauseCollection)null);
        }
        public void AddRange_Null_Item()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            coll.AddRange(new CodeCatchClause[] { null });
        }
        public void Insert_Null()
        {
            CodeCatchClauseCollection coll = new CodeCatchClauseCollection();

            coll.Insert(0, (CodeCatchClause)null);
        }