CodeExpressionCollection Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a collection of CodeExpression objects.
public ref class CodeExpressionCollection : System::Collections::CollectionBase
public class CodeExpressionCollection : System.Collections.CollectionBase
type CodeExpressionCollection = class
inherit CollectionBase
Public Class CodeExpressionCollection
Inherits CollectionBase
- Inheritance
Examples
The following example demonstrates the use of the CodeExpressionCollection class methods. The example creates a new instance of the class and uses the methods to add statements to the collection, return their index, and add or remove attributes at a specific index point.
// 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);
' 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)
Remarks
Provides a simple collection object that can represent a set of Code Document Object Model (CodeDOM) expression objects.
The CodeExpressionCollection class provides a simple collection object that can be used to store a set of CodeExpression objects.
Constructors
| Name | Description |
|---|---|
| CodeExpressionCollection() |
Initializes a new instance of the CodeExpressionCollection class. |
| CodeExpressionCollection(CodeExpression[]) |
Initializes a new instance of the CodeExpressionCollection class containing the specified array of CodeExpression objects. |
| CodeExpressionCollection(CodeExpressionCollection) |
Initializes a new instance of the CodeExpressionCollection class containing the elements of the specified source collection. |
Properties
| Name | Description |
|---|---|
| Item[Int32] |
Gets or sets the CodeExpression object at the specified index in the collection. |
Methods
| Name | Description |
|---|---|
| Add(CodeExpression) |
Adds the specified CodeExpression object to the collection. |
| AddRange(CodeExpression[]) |
Copies the elements of the specified array to the end of the collection. |
| AddRange(CodeExpressionCollection) |
Copies the contents of another CodeExpressionCollection object to the end of the collection. |
| Contains(CodeExpression) |
Gets a value that indicates whether the collection contains the specified CodeExpression object. |
| CopyTo(CodeExpression[], Int32) |
Copies the collection objects to a one-dimensional Array instance beginning at the specified index. |
| IndexOf(CodeExpression) |
Gets the index of the specified CodeExpression object in the collection, if it exists in the collection. |
| Insert(Int32, CodeExpression) |
Inserts the specified CodeExpression object into the collection at the specified index. |
| Remove(CodeExpression) |
Removes the specified CodeExpression object from the collection. |