public void Constructor1_Deny_Unrestricted() { CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(array); coll.CopyTo(array, 0); Assert.AreEqual(1, coll.Add(ctd), "Add"); Assert.AreSame(ctd, coll[0], "this[int]"); coll.AddRange(array); coll.AddRange(coll); Assert.IsTrue(coll.Contains(ctd), "Contains"); Assert.AreEqual(0, coll.IndexOf(ctd), "IndexOf"); coll.Insert(0, ctd); coll.Remove(ctd); }
public void Insert() { CodeTypeDeclaration td1 = new CodeTypeDeclaration(); CodeTypeDeclaration td2 = new CodeTypeDeclaration(); CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(); coll.Add(td1); Assert.AreEqual(1, coll.Count, "#1"); Assert.AreEqual(0, coll.IndexOf(td1), "#2"); coll.Insert(0, td2); Assert.AreEqual(2, coll.Count, "#3"); Assert.AreEqual(1, coll.IndexOf(td1), "#4"); Assert.AreEqual(0, coll.IndexOf(td2), "#5"); }
// CodeTypeDeclarationCollection public void CodeTypeDeclarationCollectionExample() { //<Snippet1> //<Snippet2> // Creates an empty CodeTypeDeclarationCollection. CodeTypeDeclarationCollection collection = new CodeTypeDeclarationCollection(); //</Snippet2> //<Snippet3> // Adds a CodeTypeDeclaration to the collection. collection.Add(new CodeTypeDeclaration("TestType")); //</Snippet3> //<Snippet4> // Adds an array of CodeTypeDeclaration objects to the collection. CodeTypeDeclaration[] declarations = { new CodeTypeDeclaration("TestType1"), new CodeTypeDeclaration("TestType2") }; collection.AddRange(declarations); // Adds a collection of CodeTypeDeclaration objects to the // collection. CodeTypeDeclarationCollection declarationsCollection = new CodeTypeDeclarationCollection(); declarationsCollection.Add(new CodeTypeDeclaration("TestType1")); declarationsCollection.Add(new CodeTypeDeclaration("TestType2")); collection.AddRange(declarationsCollection); //</Snippet4> //<Snippet5> // Tests for the presence of a CodeTypeDeclaration in the // collection, and retrieves its index if it is found. CodeTypeDeclaration testDeclaration = new CodeTypeDeclaration("TestType"); 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 CodeTypeDeclaration array. // 'declarations' is a CodeTypeDeclaration array. collection.CopyTo(declarations, 0); //</Snippet6> //<Snippet7> // Retrieves the count of the items in the collection. int collectionCount = collection.Count; //</Snippet7> //<Snippet8> // Inserts a CodeTypeDeclaration at index 0 of the collection. collection.Insert(0, new CodeTypeDeclaration("TestType")); //</Snippet8> //<Snippet9> // Removes the specified CodeTypeDeclaration from the collection. CodeTypeDeclaration declaration = new CodeTypeDeclaration("TestType"); collection.Remove(declaration); //</Snippet9> //<Snippet10> // Removes the CodeTypeDeclaration at index 0. collection.RemoveAt(0); //</Snippet10> //</Snippet1> }
public void Insert_Null() { CodeTypeDeclarationCollection coll = new CodeTypeDeclarationCollection(); coll.Insert(0, (CodeTypeDeclaration)null); }