Ejemplo n.º 1
0
        public void Constructor1()
        {
            CodeExpression exp1 = new CodeExpression();
            CodeExpression exp2 = new CodeExpression();

            CodeExpression[]         expressions = new CodeExpression[] { exp1, exp2 };
            CodeExpressionCollection coll        = new CodeExpressionCollection(
                expressions);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(exp1), "#2");
            Assert.AreEqual(1, coll.IndexOf(exp2), "#3");
        }
Ejemplo n.º 2
0
        public void Insert()
        {
            CodeExpression exp1 = new CodeExpression();
            CodeExpression exp2 = new CodeExpression();

            CodeExpressionCollection coll = new CodeExpressionCollection();

            coll.Add(exp1);
            Assert.AreEqual(1, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(exp1), "#2");
            coll.Insert(0, exp2);
            Assert.AreEqual(2, coll.Count, "#3");
            Assert.AreEqual(1, coll.IndexOf(exp1), "#4");
            Assert.AreEqual(0, coll.IndexOf(exp2), "#5");
        }
Ejemplo n.º 3
0
        public void Constructor2()
        {
            CodeExpression exp1 = new CodeExpression();
            CodeExpression exp2 = new CodeExpression();

            CodeExpressionCollection c = new CodeExpressionCollection();

            c.Add(exp1);
            c.Add(exp2);

            CodeExpressionCollection coll = new CodeExpressionCollection(c);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(exp1), "#2");
            Assert.AreEqual(1, coll.IndexOf(exp2), "#3");
        }
Ejemplo n.º 4
0
        public void Remove()
        {
            CodeExpression ce1 = new CodeExpression();
            CodeExpression ce2 = new CodeExpression();

            CodeExpressionCollection coll = new CodeExpressionCollection();

            coll.Add(ce1);
            coll.Add(ce2);
            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(ce1), "#2");
            Assert.AreEqual(1, coll.IndexOf(ce2), "#3");
            coll.Remove(ce1);
            Assert.AreEqual(1, coll.Count, "#4");
            Assert.AreEqual(-1, coll.IndexOf(ce1), "#5");
            Assert.AreEqual(0, coll.IndexOf(ce2), "#6");
        }
Ejemplo n.º 5
0
        public void AddRange()
        {
            CodeExpression exp1 = new CodeExpression();
            CodeExpression exp2 = new CodeExpression();
            CodeExpression exp3 = new CodeExpression();

            CodeExpressionCollection coll1 = new CodeExpressionCollection();

            coll1.Add(exp1);
            coll1.Add(exp2);

            CodeExpressionCollection coll2 = new CodeExpressionCollection();

            coll2.Add(exp3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(exp1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(exp2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(exp3), "#4");

            CodeExpressionCollection coll3 = new CodeExpressionCollection();

            coll3.Add(exp3);
            coll3.AddRange(new CodeExpression[] { exp1, exp2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(exp1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(exp2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(exp3), "#8");
        }
        public void Constructor1_Deny_Unrestricted()
        {
            CodeExpressionCollection coll = new CodeExpressionCollection(array);

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

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeExpression to the collection.
            collection.Add(new CodePrimitiveExpression(true));
            //</Snippet3>

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

            // Adds a collection of CodeExpression objects to the collection.
            CodeExpressionCollection expressionsCollection = new CodeExpressionCollection();

            expressionsCollection.Add(new CodePrimitiveExpression(true));
            expressionsCollection.Add(new CodePrimitiveExpression(true));
            collection.AddRange(expressionsCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a CodeExpression in the
            // collection, and retrieves its index if it is found.
            CodeExpression testComment = new CodePrimitiveExpression(true);
            int            itemIndex   = -1;

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

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

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

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeExpression at index 0 of the collection.
            collection.Insert(0, new CodePrimitiveExpression(true));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeExpression from the collection.
            CodeExpression expression = new CodePrimitiveExpression(true);

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

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