CodeTypeMemberCollection Class
.NET Framework 3.0
Represents a collection of CodeTypeMember objects.
Namespace: System.CodeDom
Assembly: System (in system.dll)
Assembly: System (in system.dll)
[SerializableAttribute] [ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] public class CodeTypeMemberCollection : CollectionBase
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ /** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ public class CodeTypeMemberCollection extends CollectionBase
SerializableAttribute ComVisibleAttribute(true) ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) public class CodeTypeMemberCollection extends CollectionBase
Not applicable.
The following code example demonstrates the use of the CodeTypeMemberCollection class. The example creates a new instance of the class and uses several methods to add statements to the collection, return their index, and add or remove attributes at a specific index point.
// Creates an empty CodeTypeMemberCollection. CodeTypeMemberCollection collection = new CodeTypeMemberCollection(); // Adds a CodeTypeMember to the collection. collection.Add( new CodeMemberField("System.String", "TestStringField") ); // Adds an array of CodeTypeMember objects to the collection. CodeTypeMember[] members = { new CodeMemberField("System.String", "TestStringField1"), new CodeMemberField("System.String", "TestStringField2") }; collection.AddRange( members ); // Adds a collection of CodeTypeMember objects to the collection. CodeTypeMemberCollection membersCollection = new CodeTypeMemberCollection(); membersCollection.Add( new CodeMemberField("System.String", "TestStringField1") ); membersCollection.Add( new CodeMemberField("System.String", "TestStringField2") ); collection.AddRange( membersCollection ); // Tests for the presence of a CodeTypeMember in the collection, // and retrieves its index if it is found. CodeTypeMember testMember = new CodeMemberField("System.String", "TestStringField"); int itemIndex = -1; if( collection.Contains( testMember ) ) itemIndex = collection.IndexOf( testMember ); // Copies the contents of the collection, beginning at index 0, // to the specified CodeTypeMember array. // 'members' is a CodeTypeMember array. collection.CopyTo( members, 0 ); // Retrieves the count of the items in the collection. int collectionCount = collection.Count; // Inserts a CodeTypeMember at index 0 of the collection. collection.Insert( 0, new CodeMemberField("System.String", "TestStringField") ); // Removes the specified CodeTypeMember from the collection. CodeTypeMember member = new CodeMemberField("System.String", "TestStringField"); collection.Remove( member ); // Removes the CodeTypeMember at index 0. collection.RemoveAt(0);
// Creates an empty CodeTypeMemberCollection.
CodeTypeMemberCollection collection = new CodeTypeMemberCollection();
// Adds a CodeTypeMember to the collection.
collection.Add(new CodeMemberField("System.String", "TestStringField"));
// Adds an array of CodeTypeMember objects to the collection.
CodeTypeMember members[] = { new CodeMemberField("System.String",
"TestStringField1"), new CodeMemberField("System.String",
"TestStringField2") };
collection.AddRange(members);
// Adds a collection of CodeTypeMember objects to the collection.
CodeTypeMemberCollection membersCollection = new
CodeTypeMemberCollection();
membersCollection.Add(new CodeMemberField("System.String",
"TestStringField1"));
membersCollection.Add(new CodeMemberField("System.String",
"TestStringField2"));
collection.AddRange(membersCollection);
// Tests for the presence of a CodeTypeMember in the collection,
// and retrieves its index if it is found.
CodeTypeMember testMember = new CodeMemberField("System.String",
"TestStringField");
int itemIndex = -1;
if (collection.Contains(testMember)) {
itemIndex = collection.IndexOf(testMember);
}
// Copies the contents of the collection, beginning at index 0,
// to the specified CodeTypeMember array.
// 'members' is a CodeTypeMember array.
collection.CopyTo(members, 0);
// Retrieves the count of the items in the collection.
int collectionCount = collection.get_Count();
// Inserts a CodeTypeMember at index 0 of the collection.
collection.Insert(0, new CodeMemberField("System.String",
"TestStringField"));
// Removes the specified CodeTypeMember from the collection.
CodeTypeMember member = new CodeMemberField("System.String",
"TestStringField");
collection.Remove(member);
// Removes the CodeTypeMember at index 0.
collection.RemoveAt(0);
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: