Beispiel #1
0
        public void Constructor1()
        {
            CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpression[]         parameters = new CodeParameterDeclarationExpression[] { param1, param2 };
            CodeParameterDeclarationExpressionCollection coll       = new CodeParameterDeclarationExpressionCollection(
                parameters);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(param1), "#2");
            Assert.AreEqual(1, coll.IndexOf(param2), "#3");
        }
Beispiel #2
0
        public void Insert()
        {
            CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection();

            coll.Add(param1);
            Assert.AreEqual(1, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(param1), "#2");
            coll.Insert(0, param2);
            Assert.AreEqual(2, coll.Count, "#3");
            Assert.AreEqual(1, coll.IndexOf(param1), "#4");
            Assert.AreEqual(0, coll.IndexOf(param2), "#5");
        }
Beispiel #3
0
        public void Constructor2()
        {
            CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpressionCollection c = new CodeParameterDeclarationExpressionCollection();

            c.Add(param1);
            c.Add(param2);

            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection(c);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(param1), "#2");
            Assert.AreEqual(1, coll.IndexOf(param2), "#3");
        }
Beispiel #4
0
        public void Remove()
        {
            CodeParameterDeclarationExpression cpde1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression cpde2 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection();

            coll.Add(cpde1);
            coll.Add(cpde2);
            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cpde1), "#2");
            Assert.AreEqual(1, coll.IndexOf(cpde2), "#3");
            coll.Remove(cpde1);
            Assert.AreEqual(1, coll.Count, "#4");
            Assert.AreEqual(-1, coll.IndexOf(cpde1), "#5");
            Assert.AreEqual(0, coll.IndexOf(cpde2), "#6");
        }
Beispiel #5
0
        public void AddRange()
        {
            CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression();
            CodeParameterDeclarationExpression param3 = new CodeParameterDeclarationExpression();

            CodeParameterDeclarationExpressionCollection coll1 = new CodeParameterDeclarationExpressionCollection();

            coll1.Add(param1);
            coll1.Add(param2);

            CodeParameterDeclarationExpressionCollection coll2 = new CodeParameterDeclarationExpressionCollection();

            coll2.Add(param3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(param1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(param2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(param3), "#4");

            CodeParameterDeclarationExpressionCollection coll3 = new CodeParameterDeclarationExpressionCollection();

            coll3.Add(param3);
            coll3.AddRange(new CodeParameterDeclarationExpression[] { param1, param2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(param1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(param2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(param3), "#8");
        }
Beispiel #6
0
        public void Constructor1_Deny_Unrestricted()
        {
            CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection(array);

            coll.CopyTo(array, 0);
            Assert.AreEqual(1, coll.Add(cpde), "Add");
            Assert.AreSame(cpde, coll[0], "this[int]");
            coll.AddRange(array);
            coll.AddRange(coll);
            Assert.IsTrue(coll.Contains(cpde), "Contains");
            Assert.AreEqual(0, coll.IndexOf(cpde), "IndexOf");
            coll.Insert(0, cpde);
            coll.Remove(cpde);
        }
        private static int PositionToParameterIndex(CodeParameterDeclarationExpressionCollection collection, object Position)
        {
            ICodeDomElement icde = Position as ICodeDomElement;

            if (icde != null)
            {
                return(collection.IndexOf((CodeParameterDeclarationExpression)icde.UntypedCodeObject) + 1);
            }

            if (Position == System.Reflection.Missing.Value)
            {
                return(collection.Count);
            }

            int pos = (int)Position;

            if (pos == -1)
            {
                return(collection.Count);
            }
            return(pos - 1);
        }
Beispiel #8
0
        // CodeParameterDeclarationExpressionCollection
        public void CodeParameterDeclarationExpressionCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeParameterDeclarationExpressionCollection.
            CodeParameterDeclarationExpressionCollection collection = new CodeParameterDeclarationExpressionCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeParameterDeclarationExpression to the collection.
            collection.Add(new CodeParameterDeclarationExpression(typeof(int), "testIntArgument"));
            //</Snippet3>

            //<Snippet4>
            // Adds an array of CodeParameterDeclarationExpression objects
            // to the collection.
            CodeParameterDeclarationExpression[] parameters = { new CodeParameterDeclarationExpression(typeof(int), "testIntArgument"), new CodeParameterDeclarationExpression(typeof(bool), "testBoolArgument") };
            collection.AddRange(parameters);

            // Adds a collection of CodeParameterDeclarationExpression objects
            // to the collection.
            CodeParameterDeclarationExpressionCollection parametersCollection = new CodeParameterDeclarationExpressionCollection();

            parametersCollection.Add(new CodeParameterDeclarationExpression(typeof(int), "testIntArgument"));
            parametersCollection.Add(new CodeParameterDeclarationExpression(typeof(bool), "testBoolArgument"));
            collection.AddRange(parametersCollection);
            //</Snippet4>

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

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

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

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

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeParameterDeclarationExpression at index 0
            // of the collection.
            collection.Insert(0, new CodeParameterDeclarationExpression(typeof(int), "testIntArgument"));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeParameterDeclarationExpression
            // from the collection.
            CodeParameterDeclarationExpression parameter = new CodeParameterDeclarationExpression(typeof(int), "testIntArgument");

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

            //<Snippet10>
            // Removes the CodeParameterDeclarationExpression at index 0.
            collection.RemoveAt(0);
            //</Snippet10>
            //</Snippet1>
        }
 public int IndexOf(DynaArgument thisArg)
 {
     return(codeArgs.IndexOf(thisArg.CodeArgument));
 }