Exemple #1
0
        public static CodeAttributeDeclarationCollection Remove(this CodeAttributeDeclarationCollection attributes, string[] names)
        {
            if (names == null || names.Length == 0)
            {
                return(attributes);
            }

            var toDelete = new List <CodeAttributeDeclaration>();

            foreach (CodeAttributeDeclaration attr in attributes)
            {
                if (names.Where(_ => _.ToUpperInvariant() == attr.Name.ToUpperInvariant()).Any())
                {
                    toDelete.Add(attr);
                }
            }

            if (toDelete.Count > 0)
            {
                foreach (CodeAttributeDeclaration attr in toDelete)
                {
                    attributes.Remove(attr);
                }
            }

            return(attributes);
        }
Exemple #2
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 #3
0
        public void Remove()
        {
            CodeAttributeDeclaration cad1 = new CodeAttributeDeclaration();
            CodeAttributeDeclaration cad2 = new CodeAttributeDeclaration();

            CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection();

            coll.Add(cad1);
            coll.Add(cad2);
            Assert.AreEqual(2, coll.Count, "#1");
            Assert.AreEqual(0, coll.IndexOf(cad1), "#2");
            Assert.AreEqual(1, coll.IndexOf(cad2), "#3");
            coll.Remove(cad1);
            Assert.AreEqual(1, coll.Count, "#4");
            Assert.AreEqual(-1, coll.IndexOf(cad1), "#5");
            Assert.AreEqual(0, coll.IndexOf(cad2), "#6");
        }
Exemple #4
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 #5
0
        public void Remove_Null()
        {
            CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection();

            coll.Remove((CodeAttributeDeclaration)null);
        }
Exemple #6
0
        public void Remove_NotInCollection()
        {
            CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection();

            coll.Remove(new CodeAttributeDeclaration());
        }