BreakpointTargetEnumerator.Current 屬性

定義

取得集合中目前的 BreakpointTarget 物件。

public:
 property Microsoft::SqlServer::Dts::Runtime::BreakpointTarget ^ Current { Microsoft::SqlServer::Dts::Runtime::BreakpointTarget ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.BreakpointTarget Current { get; }
member this.Current : Microsoft.SqlServer.Dts.Runtime.BreakpointTarget
Public ReadOnly Property Current As BreakpointTarget

屬性值

BreakpointTarget

集合中目前的 BreakpointTarget 物件。

範例

下列程式碼範例會建立枚舉器,然後使用 CurrentMoveNext 方法來流覽集合。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
using Microsoft.SqlServer.Dts.Tasks.BulkInsertTask;  

namespace BreakpointTarget_Expression  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            TaskHost taskHost = (TaskHost)pkg.Executables.Add("STOCK:FileSystemTask");  
            BreakpointTargets bptargets = pkg.GetBreakpointTargets(taskHost, false);  
            // Create the enumerator.  
            BreakpointTargetEnumerator myEnumerator = bptargets.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
                Console.WriteLine("[{0}] {1}", i++, myEnumerator.Current.Description);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Imports Microsoft.SqlServer.Dts.Tasks.BulkInsertTask  

Namespace BreakpointTarget_Expression  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   
            Dim taskHost As TaskHost = CType(pkg.Executables.Add("STOCK:FileSystemTask"), TaskHost)  
            Dim bptargets As BreakpointTargets =  pkg.GetBreakpointTargets(taskHost,False)   
            ' Create the enumerator.  
            Dim myEnumerator As BreakpointTargetEnumerator =  bptargets.GetEnumerator()   
            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)  
            Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1  
            End While  
        End Sub  
    End Class  
End Namespace  

範例輸出:

集合包含下列值:

[0] 當容器收到 OnPreExecute 事件時中斷

[1] 當容器收到 OnPostExecute 事件時中斷

[2] 當容器收到 OnError 事件時中斷

[3] 當容器收到 OnWarning 事件時中斷

[4] 當容器收到 OnInformation 事件時中斷

[5] 當容器收到 OnTaskFailed 事件時中斷

[6] 當容器收到 OnProgress 事件時中斷

[7] 當容器收到 OnQueryCancel 事件時中斷

[8] 當容器收到 OnVariableValueChanged 事件時中斷

[9] 當容器收到 OnCustomEvent 事件時中斷

備註

建立枚舉器之後,或呼叫 Reset 方法之後, MoveNext 必須呼叫方法,將列舉值前移至集合的第一個元素,然後再讀取屬性的值 Current ; 否則, Current 是未知的,而且會擲回例外狀況。

Current如果最後一個呼叫 MoveNext 傳回 false ,表示集合的結尾,也會擲回例外狀況。

Current不會移動列舉值的位置,而連續的呼叫會傳回 Current 相同的物件,直到 MoveNext 呼叫或為止 Reset

只要集合維持不變,列舉值就仍維持有效。 如果對集合進行了變更,例如加入、修改或刪除專案,枚舉器會失效且無法復原,因此下一次呼叫或時,會擲回 MoveNext Reset InvalidOperationException 。 如果在和之間修改集合 MoveNext Current ,則 Current 會傳回其設定的元素,即使列舉值已經無效也一樣。

適用於