Exemple #1
0
        public void Constructor1_Deny_Unrestricted()
        {
            CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection(array);

            coll.CopyTo(array, 0);
            Assert.AreEqual(1, coll.Add(cad), "Add");
            Assert.AreSame(cad, coll[0], "this[int]");
            coll.AddRange(array);
            coll.AddRange(coll);
            Assert.IsTrue(coll.Contains(cad), "Contains");
            Assert.AreEqual(0, coll.IndexOf(cad), "IndexOf");
            coll.Insert(0, cad);
            coll.Remove(cad);
        }
Exemple #2
0
 public void AddMemberAttributes(XmlName messageName, MessagePartDescription part, CodeAttributeDeclarationCollection importedAttributes, CodeAttributeDeclarationCollection typeAttributes, CodeAttributeDeclarationCollection fieldAttributes)
 {
     if (importedAttributes != null)
     {
         fieldAttributes.AddRange(importedAttributes);
     }
 }
Exemple #3
0
        public static CodeAttributeDeclarationCollection Add(this CodeAttributeDeclarationCollection attributes, string[] names)
        {
            if (names == null || names.Length == 0)
            {
                return(attributes);
            }

            var toAdd = new List <CodeAttributeDeclaration>();

            if (attributes.Count > 0)
            {
                names
                .Where(_ => attributes.Contains(new CodeAttributeDeclaration(_)) == false)?
                .ToList()
                .ForEach(_ => toAdd.Add(new CodeAttributeDeclaration(_)));
            }
            else
            {
                names
                .ToList()
                .ForEach(_ => toAdd.Add(new CodeAttributeDeclaration(_)));
            }

            if (toAdd.Count > 0)
            {
                attributes.AddRange(toAdd.ToArray());
            }

            return(attributes);
        }
Exemple #4
0
        public void AddRange()
        {
            CodeAttributeDeclaration cad1 = new CodeAttributeDeclaration();
            CodeAttributeDeclaration cad2 = new CodeAttributeDeclaration();
            CodeAttributeDeclaration cad3 = new CodeAttributeDeclaration();

            CodeAttributeDeclarationCollection coll1 = new CodeAttributeDeclarationCollection();

            coll1.Add(cad1);
            coll1.Add(cad2);

            CodeAttributeDeclarationCollection coll2 = new CodeAttributeDeclarationCollection();

            coll2.Add(cad3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(cad1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(cad2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(cad3), "#4");

            CodeAttributeDeclarationCollection coll3 = new CodeAttributeDeclarationCollection();

            coll3.Add(cad3);
            coll3.AddRange(new CodeAttributeDeclaration[] { cad1, cad2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(cad1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(cad2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(cad3), "#8");
        }
        /// <summary>
        /// Visits a <see cref="CodeAttributeDeclarationCollection"/>.
        /// </summary>
        /// <param name="codeAttributeDeclarationCollection">The <see cref="CodeAttributeDeclarationCollection"/> to visit.</param>
        protected override void VisitCodeAttributeDeclarationCollection(CodeAttributeDeclarationCollection codeAttributeDeclarationCollection)
        {
            CodeAttributeDeclaration[] sortedAttributes = codeAttributeDeclarationCollection.Cast <CodeAttributeDeclaration>().OrderBy(a => GetAttributeId(a)).ToArray();
            codeAttributeDeclarationCollection.Clear();
            codeAttributeDeclarationCollection.AddRange(sortedAttributes);

            base.VisitCodeAttributeDeclarationCollection(codeAttributeDeclarationCollection);
        }
Exemple #6
0
        public void AddRange_Self()
        {
            CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection();

            coll.Add(new CodeAttributeDeclaration());
            Assert.AreEqual(1, coll.Count, "#1");
            coll.AddRange(coll);
            Assert.AreEqual(2, coll.Count, "#2");
        }
Exemple #7
0
        // CodeAttributeDeclarationCollection
        public void CodeAttributeDeclarationCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeAttributeDeclarationCollection.
            CodeAttributeDeclarationCollection collection = new CodeAttributeDeclarationCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeAttributeDeclaration to the collection.
            collection.Add(new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))));
            //</Snippet3>

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

            // Adds a collection of CodeAttributeDeclaration objects
            // to the collection.
            CodeAttributeDeclarationCollection declarationsCollection = new CodeAttributeDeclarationCollection();

            declarationsCollection.Add(new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))));
            declarationsCollection.Add(new CodeAttributeDeclaration("BrowsableAttribute", new CodeAttributeArgument(new CodePrimitiveExpression(true))));
            collection.AddRange(declarationsCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a CodeAttributeDeclaration in
            // the collection, and retrieves its index if it is found.
            CodeAttributeDeclaration testdeclaration = new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description")));
            int itemIndex = -1;

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

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

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

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeAttributeDeclaration at index 0 of the collection.
            collection.Insert(0, new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeAttributeDeclaration from
            // the collection.
            CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description")));

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

            //<Snippet10>
            // Removes the CodeAttributeDeclaration at index 0.
            collection.RemoveAt(0);
            //</Snippet10>
            //</Snippet1>
        }
Exemple #8
0
        public void AddRange_Null_Collection()
        {
            CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection();

            coll.AddRange((CodeAttributeDeclarationCollection)null);
        }
Exemple #9
0
        public void AddRange_Null_Item()
        {
            CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection();

            coll.AddRange(new CodeAttributeDeclaration[] { null });
        }