CompilerErrorCollection 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 CompilerError objects.
public ref class CompilerErrorCollection : System::Collections::CollectionBase
public class CompilerErrorCollection : System.Collections.CollectionBase
type CompilerErrorCollection = class
inherit CollectionBase
Public Class CompilerErrorCollection
Inherits CollectionBase
- Inheritance
Examples
The following example demonstrates how to use the CompilerErrorCollection 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 CompilerErrorCollection.
CompilerErrorCollection collection = new CompilerErrorCollection();
// Adds a CompilerError to the collection.
collection.Add( new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text") );
// Adds an array of CompilerError objects to the collection.
CompilerError[] errors = { new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text"), new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text") };
collection.AddRange( errors );
// Adds a collection of CompilerError objects to the collection.
CompilerErrorCollection errorsCollection = new CompilerErrorCollection();
errorsCollection.Add( new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text") );
errorsCollection.Add( new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text") );
collection.AddRange( errorsCollection );
// Tests for the presence of a CompilerError in the
// collection, and retrieves its index if it is found.
CompilerError testError = new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text");
int itemIndex = -1;
if( collection.Contains( testError ) )
itemIndex = collection.IndexOf( testError );
// Copies the contents of the collection, beginning at index 0,
// to the specified CompilerError array.
// 'errors' is a CompilerError array.
collection.CopyTo( errors, 0 );
// Retrieves the count of the items in the collection.
int collectionCount = collection.Count;
// Inserts a CompilerError at index 0 of the collection.
collection.Insert( 0, new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text") );
// Removes the specified CompilerError from the collection.
CompilerError error = new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text");
collection.Remove( error );
// Removes the CompilerError at index 0.
collection.RemoveAt(0);
' Creates an empty CompilerErrorCollection.
Dim collection As New CompilerErrorCollection()
' Adds a CompilerError to the collection.
collection.Add(New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text"))
' Adds an array of CompilerError objects to the collection.
Dim errors As CompilerError() = {New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text"), New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text")}
collection.AddRange(errors)
' Adds a collection of CompilerError objects to the collection.
Dim errorsCollection As New CompilerErrorCollection()
errorsCollection.Add(New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text"))
errorsCollection.Add(New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text"))
collection.AddRange(errorsCollection)
' Tests for the presence of a CompilerError in the
' collection, and retrieves its index if it is found.
Dim testError As New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text")
Dim itemIndex As Integer = -1
If collection.Contains(testError) Then
itemIndex = collection.IndexOf(testError)
End If
' Copies the contents of the collection, beginning at index 0,
' to the specified CompilerError array.
' 'errors' is a CompilerError array.
collection.CopyTo(errors, 0)
' Retrieves the count of the items in the collection.
Dim collectionCount As Integer = collection.Count
' Inserts a CompilerError at index 0 of the collection.
collection.Insert(0, New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text"))
' Removes the specified CompilerError from the collection.
Dim [error] As New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text")
collection.Remove([error])
' Removes the CompilerError at index 0.
collection.RemoveAt(0)
Remarks
The CompilerErrorCollection class provides a simple collection object that can be used to store a set of CompilerError objects.
Note
This class contains an inheritance demand at the class level that applies to all members. A SecurityException is thrown when the derived class does not have full-trust permission.
Constructors
| Name | Description |
|---|---|
| CompilerErrorCollection() |
Initializes a new instance of the CompilerErrorCollection class. |
| CompilerErrorCollection(CompilerError[]) |
Initializes a new instance of CompilerErrorCollection that contains the specified array of CompilerError objects. |
| CompilerErrorCollection(CompilerErrorCollection) |
Initializes a new instance of the CompilerErrorCollection class that contains the contents of the specified CompilerErrorCollection. |
Properties
| Name | Description |
|---|---|
| HasErrors |
Gets a value that indicates whether the collection contains errors. |
| HasWarnings |
Gets a value that indicates whether the collection contains warnings. |
| Item[Int32] |
Gets or sets the CompilerError at the specified index. |
Methods
| Name | Description |
|---|---|
| Add(CompilerError) |
Adds the specified CompilerError object to the error collection. |
| AddRange(CompilerError[]) |
Copies the elements of an array to the end of the error collection. |
| AddRange(CompilerErrorCollection) |
Adds the contents of the specified compiler error collection to the end of the error collection. |
| Contains(CompilerError) |
Gets a value that indicates whether the collection contains the specified CompilerError object. |
| CopyTo(CompilerError[], Int32) |
Copies the collection values to a one-dimensional Array instance at the specified index. |
| IndexOf(CompilerError) |
Gets the index of the specified CompilerError object in the collection, if it exists in the collection. |
| Insert(Int32, CompilerError) |
Inserts the specified CompilerError into the collection at the specified index. |
| Remove(CompilerError) |
Removes a specific CompilerError from the collection. |