Export (0) Print
Expand All

CodeExpressionCollection Class

Represents a collection of CodeExpression objects.

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

System.Object
   System.Collections.CollectionBase
      System.CodeDom.CodeExpressionCollection

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeExpressionCollection
   Inherits CollectionBase
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeExpressionCollection : CollectionBase
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeExpressionCollection : public
   CollectionBase
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeExpressionCollection 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

Provides a simple collection object that can represent a set of CodeDOM expression objects.

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

Example

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

' Adds a CodeExpression to the collection.
collection.Add(New CodePrimitiveExpression(True))

' Adds an array of CodeExpression objects to the collection.
Dim expressions As CodeExpression() = {New CodePrimitiveExpression(True), New CodePrimitiveExpression(True)}
collection.AddRange(expressions)

' Adds a collection of CodeExpression objects to the collection.
Dim expressionsCollection As New CodeExpressionCollection()
expressionsCollection.Add(New CodePrimitiveExpression(True))
expressionsCollection.Add(New CodePrimitiveExpression(True))
collection.AddRange(expressionsCollection)

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

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

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

' Inserts a CodeExpression at index 0 of the collection.
collection.Insert(0, New CodePrimitiveExpression(True))

' Removes the specified CodeExpression from the collection.
Dim expression = New CodePrimitiveExpression(True)
collection.Remove(expression)

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

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

// Adds a CodeExpression to the collection.
collection.Add( new CodePrimitiveExpression(true) );

// Adds an array of CodeExpression objects to the collection.
CodeExpression[] expressions = { new CodePrimitiveExpression(true), new CodePrimitiveExpression(true) };
collection.AddRange( expressions );

// Adds a collection of CodeExpression objects to the collection.
CodeExpressionCollection expressionsCollection = new CodeExpressionCollection();
expressionsCollection.Add( new CodePrimitiveExpression(true) );
expressionsCollection.Add( new CodePrimitiveExpression(true) );
collection.AddRange( expressionsCollection );

// Tests for the presence of a CodeExpression in the 
// collection, and retrieves its index if it is found.
CodeExpression testComment = new CodePrimitiveExpression(true);
int itemIndex = -1;
if( collection.Contains( testComment ) )
    itemIndex = collection.IndexOf( testComment );

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

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

// Inserts a CodeExpression at index 0 of the collection.
collection.Insert( 0, new CodePrimitiveExpression(true) );

// Removes the specified CodeExpression from the collection.
CodeExpression expression = new CodePrimitiveExpression(true);
collection.Remove( expression );

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

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

// Adds a CodeExpression to the collection.
collection->Add( new CodePrimitiveExpression(__box(true)) );

// Adds an array of CodeExpression objects to the collection.
CodeExpression* expressions[] = { new CodePrimitiveExpression(__box(true)), new CodePrimitiveExpression(__box(true)) };
collection->AddRange( expressions );

// Adds a collection of CodeExpression objects to the collection.
CodeExpressionCollection* expressionsCollection = new CodeExpressionCollection();
expressionsCollection->Add( new CodePrimitiveExpression(__box(true)) );
expressionsCollection->Add( new CodePrimitiveExpression(__box(true)) );
collection->AddRange( expressionsCollection );

// Tests for the presence of a CodeExpression in the 
// collection, and retrieves its index if it is found.
CodeExpression* testComment = new CodePrimitiveExpression(__box(true));
int itemIndex = -1;
if( collection->Contains( testComment ) )
    itemIndex = collection->IndexOf( testComment );

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

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

// Inserts a CodeExpression at index 0 of the collection.
collection->Insert( 0, new CodePrimitiveExpression(__box(true)) );

// Removes the specified CodeExpression from the collection.
CodeExpression* expression = new CodePrimitiveExpression(__box(true));
collection->Remove( expression );

// Removes the CodeExpression 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

CodeExpressionCollection Members | System.CodeDom Namespace | CodeExpression

Show:
© 2014 Microsoft