Export (0) Print
Expand All

CodeTypeDeclarationCollection Class

Represents a collection of CodeTypeDeclaration objects.

For a list of all members of this type, see CodeTypeDeclarationCollection Members.

System.Object
   System.Collections.CollectionBase
      System.CodeDom.CodeTypeDeclarationCollection

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeTypeDeclarationCollection
   Inherits CollectionBase
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeTypeDeclarationCollection : CollectionBase
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeTypeDeclarationCollection : public
   CollectionBase
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeTypeDeclarationCollection extends CollectionBase

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The CodeTypeDeclarationCollection class provides a simple collection object that can be used to store a set of CodeTypeDeclaration objects.

Example

[Visual Basic] 
' Creates an empty CodeTypeDeclarationCollection.
Dim collection As New CodeTypeDeclarationCollection()

' Adds a CodeTypeDeclaration to the collection.
collection.Add(New CodeTypeDeclaration("TestType"))

' Adds an array of CodeTypeDeclaration objects to the 
' collection.
Dim declarations As CodeTypeDeclaration() = {New CodeTypeDeclaration("TestType1"), New CodeTypeDeclaration("TestType2")}
collection.AddRange(declarations)

' Adds a collection of CodeTypeDeclaration objects to the collection.
Dim declarationsCollection As New CodeTypeDeclarationCollection()
declarationsCollection.Add(New CodeTypeDeclaration("TestType1"))
declarationsCollection.Add(New CodeTypeDeclaration("TestType2"))
collection.AddRange(declarationsCollection)

' Tests for the presence of a CodeTypeDeclaration in the 
' collection, and retrieves its index if it is found.
Dim testDeclaration As New CodeTypeDeclaration("TestType")
Dim itemIndex As Integer = -1
If collection.Contains(testDeclaration) Then
    itemIndex = collection.IndexOf(testDeclaration)
End If

' Copies the contents of the collection, beginning at index 0,
' to the specified CodeTypeDeclaration array.
' 'declarations' is a CodeTypeDeclaration array.
collection.CopyTo(declarations, 0)

' Retrieves the count of the items in the collection.
Dim collectionCount As Integer = collection.Count

' Inserts a CodeTypeDeclaration at index 0 of the collection.
collection.Insert(0, New CodeTypeDeclaration("TestType"))

' Removes the specified CodeTypeDeclaration from the collection.
Dim declaration As New CodeTypeDeclaration("TestType")
collection.Remove(declaration)

' Removes the CodeTypeDeclaration at index 0.
collection.RemoveAt(0)

[C#] 
// Creates an empty CodeTypeDeclarationCollection.
CodeTypeDeclarationCollection collection = new CodeTypeDeclarationCollection();

// Adds a CodeTypeDeclaration to the collection.
collection.Add( new CodeTypeDeclaration("TestType") );

// 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 );

// 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 );

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

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

// Inserts a CodeTypeDeclaration at index 0 of the collection.
collection.Insert( 0, new CodeTypeDeclaration("TestType") );

// Removes the specified CodeTypeDeclaration from the collection.
CodeTypeDeclaration declaration = new CodeTypeDeclaration("TestType");
collection.Remove( declaration );

// Removes the CodeTypeDeclaration at index 0.
collection.RemoveAt(0);

[C++] 
// Creates an empty CodeTypeDeclarationCollection.
CodeTypeDeclarationCollection* collection = new CodeTypeDeclarationCollection();

// Adds a CodeTypeDeclaration to the collection.
collection->Add( new CodeTypeDeclaration(S"TestType") );

// Adds an array of CodeTypeDeclaration objects to the collection.
CodeTypeDeclaration* declarations[] = { new CodeTypeDeclaration(S"TestType1"), new CodeTypeDeclaration(S"TestType2") };
collection->AddRange( declarations );

// Adds a collection of CodeTypeDeclaration objects to the 
// collection.
CodeTypeDeclarationCollection* declarationsCollection = new CodeTypeDeclarationCollection();
declarationsCollection->Add( new CodeTypeDeclaration(S"TestType1") );
declarationsCollection->Add( new CodeTypeDeclaration(S"TestType2") );
collection->AddRange( declarationsCollection );

// Tests for the presence of a CodeTypeDeclaration in the 
// collection, and retrieves its index if it is found.
CodeTypeDeclaration* testDeclaration = new CodeTypeDeclaration(S"TestType");
int itemIndex = -1;
if( collection->Contains( testDeclaration ) )
    itemIndex = collection->IndexOf( testDeclaration );

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

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

// Inserts a CodeTypeDeclaration at index 0 of the collection.
collection->Insert( 0, new CodeTypeDeclaration(S"TestType") );

// Removes the specified CodeTypeDeclaration from the collection.
CodeTypeDeclaration* declaration = new CodeTypeDeclaration(S"TestType");
collection->Remove( declaration );

// Removes the CodeTypeDeclaration at index 0.
collection->RemoveAt(0);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.CodeDom

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CodeTypeDeclarationCollection Members | System.CodeDom Namespace | CodeTypeDeclaration

Show:
© 2014 Microsoft