ParserErrorCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
管理在解析過程中偵測到的一組解析器錯誤。 此類別無法獲得繼承。
public ref class ParserErrorCollection sealed : System::Collections::CollectionBase
[System.Serializable]
public sealed class ParserErrorCollection : System.Collections.CollectionBase
[<System.Serializable>]
type ParserErrorCollection = class
inherit CollectionBase
Public NotInheritable Class ParserErrorCollection
Inherits CollectionBase
- 繼承
- 屬性
範例
以下程式碼範例示範如何使用這些 ParserErrorCollection 方法。
// Create an empty ParserErrorCollection.
ParserErrorCollection collection = new ParserErrorCollection();
// Add a ParserError to the collection.
collection.Add(new ParserError("ErrorName", "Path", 1));
// Add an array of ParserError objects to the collection.
ParserError[] errors =
{ new ParserError("Error 2", "Path", 1),
new ParserError("Error 3", "Path", 1) };
collection.AddRange(errors);
// Add a collection of ParserError objects to the collection.
ParserErrorCollection errorsCollection = new ParserErrorCollection();
errorsCollection.Add(new ParserError("Error", "Path", 1));
errorsCollection.Add(new ParserError("Error", "Path", 1));
collection.AddRange(errorsCollection);
// Test for the presence of a ParserError in the
// collection, and retrieve its index if it is found.
ParserError testError = new ParserError("Error", "Path", 1);
int itemIndex = -1;
if (collection.Contains(testError))
itemIndex = collection.IndexOf(testError);
// Copy the contents of the collection to a
// compatible array, starting at index 0 of the
// destination array.
ParserError[] errorsToSort = new ParserError[5];
collection.CopyTo(errorsToSort, 0);
// Retrieve the count of the items in the collection.
int collectionCount = collection.Count;
// Insert a ParserError at index 0 of the collection.
ParserError error = new ParserError("Error", "Path", 1);
collection.Insert(0, error);
// Remove the specified ParserError from the collection.
collection.Remove(error);
// Remove the ParserError at index 0.
collection.RemoveAt(0);
' Create an empty ParserErrorCollection.
Dim collection As New ParserErrorCollection()
' Add a ParserError to the collection.
collection.Add(New ParserError("ErrorName", "Path", 1))
' Add an array of ParserError objects to the collection.
Dim errors As ParserError() = _
{New ParserError("Error 2", "Path", 1), _
New ParserError("Error 3", "Path", 1)}
collection.AddRange(errors)
' Ads a collection of ParserError objects to the collection.
Dim errorsCollection As New ParserErrorCollection()
errorsCollection.Add(New ParserError("Error", "Path", 1))
errorsCollection.Add(New ParserError("Error", "Path", 1))
collection.AddRange(errorsCollection)
' Test for the presence of a ParserError in the
' collection, and retrieve its index if it is found.
Dim testError As New ParserError("Error", "Path", 1)
Dim itemIndex As Integer = -1
If collection.Contains(testError) Then
itemIndex = collection.IndexOf(testError)
End If
' Copy the contents of the collection to a
' compatible array, starting at index 0 of the
' destination array.
Dim errorsToSort(5) As ParserError
collection.CopyTo(errorsToSort, 0)
' Retrieve the count of the items in the collection.
Dim collectionCount As Integer = collection.Count
' Insert a ParserError at index 0 of the collection.
Dim [error] As New ParserError("Error", "Path", 1)
collection.Insert(0, [error])
' Remove the specified ParserError from the collection.
collection.Remove([error])
' Remove the ParserError at index 0.
collection.RemoveAt(0)
備註
這個 ParserErrorCollection 類別提供了你可以用來管理一組 ParserError 物件的方法和屬性。 例如,你可以在解析時加入一組解析器錯誤,同時使用自訂 BuildProvider 物件回報解析中捕捉到的所有解析異常。
要在集合中新增、移除或定位解析器錯誤,請使用以下工具:
將 Add 單一 ParserError 物件加入集合的方法。
新增 AddRange 多個 ParserError 物件到集合的方法。
同時使用Insert方法與Item[]ParserErrorCollection屬性(索引器)在指定索引處將單一ParserError物件加入集合。
此外,你也可以利用這 ParserErrorCollection 門課做以下事情:
用這個ParserError方法移除Remove物品。
使用該ParserError方法檢查某個特定Contains對象是否在該集合中。
透過使用此ParserError方法找出物件在集合中的位置IndexOf。
建構函式
| 名稱 | Description |
|---|---|
| ParserErrorCollection() |
初始化 ParserErrorCollection 類別的新執行個體。 |
| ParserErrorCollection(ParserError[]) |
初始化 ParserErrorCollection 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Capacity |
取得或設定 CollectionBase 可以包含的項目數目。 (繼承來源 CollectionBase) |
| Count |
取得該實例中包含 CollectionBase 的元素數量。 此屬性無法覆寫。 (繼承來源 CollectionBase) |
| InnerList |
取得包含實ArrayList例中元素清單的 。CollectionBase (繼承來源 CollectionBase) |
| Item[Int32] |
在集合中取得或設定 ParserError 物件在指定的索引位置。 |
| List |
取得包含實IList例中元素清單的 。CollectionBase (繼承來源 CollectionBase) |
方法
明確介面實作
| 名稱 | Description |
|---|---|
| ICollection.CopyTo(Array, Int32) |
從目標陣列的指定索引開始,將整個 CollectionBase 複製到相容的一維 Array。 (繼承來源 CollectionBase) |
| ICollection.IsSynchronized |
取得值,指出是否同步存取 CollectionBase (線程安全)。 (繼承來源 CollectionBase) |
| ICollection.SyncRoot |
取得一個物件,可用來同步存取 CollectionBase。 (繼承來源 CollectionBase) |
| IList.Add(Object) |
將物件加入至 CollectionBase的結尾。 (繼承來源 CollectionBase) |
| IList.Contains(Object) |
判斷是否 CollectionBase 包含特定元素。 (繼承來源 CollectionBase) |
| IList.IndexOf(Object) |
搜尋指定的 Object,並傳回整個 CollectionBase內第一個出現專案的以零起始的索引。 (繼承來源 CollectionBase) |
| IList.Insert(Int32, Object) |
將專案插入指定索引處的 CollectionBase。 (繼承來源 CollectionBase) |
| IList.IsFixedSize |
取得值,指出 CollectionBase 是否有固定大小。 (繼承來源 CollectionBase) |
| IList.IsReadOnly |
取得值,指出 CollectionBase 是否為唯讀。 (繼承來源 CollectionBase) |
| IList.Item[Int32] |
取得或設定位於指定索引處的專案。 (繼承來源 CollectionBase) |
| IList.Remove(Object) |
從 CollectionBase移除第一個出現的特定物件。 (繼承來源 CollectionBase) |
擴充方法
| 名稱 | Description |
|---|---|
| AsParallel(IEnumerable) |
啟用查詢的平行處理。 |
| AsQueryable(IEnumerable) |
將 IEnumerable 轉換成 IQueryable。 |
| Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
| OfType<TResult>(IEnumerable) |
根據指定的型別篩選 IEnumerable 的專案。 |