public void AddRange()
        {
            CodeAttributeArgument caa1 = new CodeAttributeArgument();
            CodeAttributeArgument caa2 = new CodeAttributeArgument();
            CodeAttributeArgument caa3 = new CodeAttributeArgument();

            CodeAttributeArgumentCollection coll1 = new CodeAttributeArgumentCollection();

            coll1.Add(caa1);
            coll1.Add(caa2);

            CodeAttributeArgumentCollection coll2 = new CodeAttributeArgumentCollection();

            coll2.Add(caa3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(caa1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(caa2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(caa3), "#4");

            CodeAttributeArgumentCollection coll3 = new CodeAttributeArgumentCollection();

            coll3.Add(caa3);
            coll3.AddRange(new CodeAttributeArgument[] { caa1, caa2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(caa1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(caa2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(caa3), "#8");
        }
Exemplo n.º 2
0
        static CodeAttributeArgumentCollection _ParseCustomAttributeArguments(_PC pc)
        {
            var result = new CodeAttributeArgumentCollection();

            if (ST.lparen != pc.SymbolId)
            {
                return(result);
            }
            if (!pc.Advance())
            {
                throw new ArgumentException("Unterminated argument list", "input");
            }
            var named = false;

            while (ST.rparen != pc.SymbolId)
            {
                var arg = new CodeAttributeArgument();
                if (ST.identifier == pc.SymbolId)
                {
                    var s   = pc.Value;
                    var pc2 = pc.GetLookAhead();
                    pc2.EnsureStarted();
                    pc2.Advance();
                    _SkipComments(pc2);
                    if (ST.eq == pc2.SymbolId)
                    {
                        pc.Advance();
                        _SkipComments(pc);
                        pc.Advance();
                        arg.Name  = s;
                        arg.Value = _ParseExpression(pc);
                        result.Add(arg);
                        named = true;
                        continue;
                    }
                }
                if (named)
                {
                    throw new ArgumentException("Named custom attribute arguments must follow the unnamed arguments.", "input");
                }
                var exp = _ParseExpression(pc);
                _SkipComments(pc);
                arg.Value = exp;
                result.Add(arg);
                if (ST.comma == pc.SymbolId)
                {
                    if (!pc.Advance())
                    {
                        throw new ArgumentException("Unterminated argument list.", "input");
                    }
                }
            }
            if (ST.rparen != pc.SymbolId)
            {
                throw new ArgumentException("Unterminated argument list.", "input");
            }
            pc.Advance();
            return(result);
        }
        public void Add()
        {
            CodeAttributeArgument caa1 = new CodeAttributeArgument();
            CodeAttributeArgument caa2 = new CodeAttributeArgument();

            CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection();

            Assert.AreEqual(0, coll.Add(caa1), "#1");
            Assert.AreEqual(1, coll.Count, "#2");
            Assert.AreEqual(0, coll.IndexOf(caa1), "#3");

            Assert.AreEqual(1, coll.Add(caa2), "#4");
            Assert.AreEqual(2, coll.Count, "#5");
            Assert.AreEqual(1, coll.IndexOf(caa2), "#6");
        }
        public void Constructor2()
        {
            CodeAttributeArgument caa1 = new CodeAttributeArgument();
            CodeAttributeArgument caa2 = new CodeAttributeArgument();

            CodeAttributeArgumentCollection c = new CodeAttributeArgumentCollection();

            c.Add(caa1);
            c.Add(caa2);

            CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(c);

            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(caa1), "#2");
            Assert.AreEqual(1, coll.IndexOf(caa2), "#3");
        }
Exemplo n.º 5
0
 public void CloneAttributeArguments(CodeAttributeArgumentCollection source, CodeAttributeArgumentCollection dest)
 {
     dest.Clear();
     foreach (CodeAttributeArgument arg in source)
     {
         dest.Add(CloneAttributeArgument(arg));
     }
 }
        public void AddRange_Self()
        {
            CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection();

            coll.Add(new CodeAttributeArgument());
            Assert.AreEqual(1, coll.Count, "#1");
            coll.AddRange(coll);
            Assert.AreEqual(2, coll.Count, "#2");
        }
        public void Constructor1_Deny_Unrestricted()
        {
            CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(array);

            coll.CopyTo(array, 0);
            Assert.AreEqual(1, coll.Add(caa), "Add");
            Assert.AreSame(caa, coll[0], "this[int]");
            coll.AddRange(array);
            coll.AddRange(coll);
            Assert.IsTrue(coll.Contains(caa), "Contains");
            Assert.AreEqual(0, coll.IndexOf(caa), "IndexOf");
            coll.Insert(0, caa);
            coll.Remove(caa);
        }
Exemplo n.º 8
0
        public static CodeAttributeArgumentCollection Clone(this CodeAttributeArgumentCollection collection)
        {
            if (collection == null)
            {
                return(null);
            }
            CodeAttributeArgumentCollection c = new CodeAttributeArgumentCollection();

            foreach (CodeAttributeArgument argument in collection)
            {
                c.Add(argument.Clone());
            }
            return(c);
        }
Exemplo n.º 9
0
        void AddOutputCacheAttribute()
        {
            CodeAttributeDeclaration cad;

            cad = new CodeAttributeDeclaration("System.Web.UI.PartialCachingAttribute");
            CodeAttributeArgumentCollection arguments = cad.Arguments;

            AddPrimitiveArgument(arguments, parser.OutputCacheDuration);
            AddPrimitiveArgument(arguments, parser.OutputCacheVaryByParam);
            AddPrimitiveArgument(arguments, parser.OutputCacheVaryByControls);
            AddPrimitiveArgument(arguments, parser.OutputCacheVaryByCustom);
            AddPrimitiveArgument(arguments, parser.OutputCacheSqlDependency);
            AddPrimitiveArgument(arguments, parser.OutputCacheShared);
            arguments.Add(new CodeAttributeArgument("ProviderName", new CodePrimitiveExpression(parser.ProviderName)));
            mainClass.CustomAttributes.Add(cad);
        }
Exemplo n.º 10
0
        // CodeAttributeArgumentCollection
        public void CodeAttributeArgumentCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeAttributeArgumentCollection.
            CodeAttributeArgumentCollection collection = new CodeAttributeArgumentCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeAttributeArgument to the collection.
            collection.Add(new CodeAttributeArgument("Test Boolean Argument", new CodePrimitiveExpression(true)));
            //</Snippet3>

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

            // Adds a collection of CodeAttributeArgument objects to
            // the collection.
            CodeAttributeArgumentCollection argumentsCollection = new CodeAttributeArgumentCollection();

            argumentsCollection.Add(new CodeAttributeArgument("TestBooleanArgument", new CodePrimitiveExpression(true)));
            argumentsCollection.Add(new CodeAttributeArgument("TestIntArgument", new CodePrimitiveExpression(1)));
            collection.AddRange(argumentsCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a CodeAttributeArgument
            // within the collection, and retrieves its index if it is found.
            CodeAttributeArgument testArgument = new CodeAttributeArgument("Test Boolean Argument", new CodePrimitiveExpression(true));
            int itemIndex = -1;

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

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

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

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeAttributeArgument at index 0 of the collection.
            collection.Insert(0, new CodeAttributeArgument("Test Boolean Argument", new CodePrimitiveExpression(true)));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeAttributeArgument from the collection.
            CodeAttributeArgument argument = new CodeAttributeArgument("Test Boolean Argument", new CodePrimitiveExpression(true));

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

            //<Snippet10>
            // Removes the CodeAttributeArgument at index 0.
            collection.RemoveAt(0);
            //</Snippet10>
            //</Snippet1>
        }
Exemplo n.º 11
0
 void AddPrimitiveArgument(CodeAttributeArgumentCollection arguments, object obj)
 {
     arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(obj)));
 }
        public void Add_Null()
        {
            CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection();

            coll.Add((CodeAttributeArgument)null);
        }