语言

ExecutableEnumerator.Current 属性

定义

获取集合中的当前元素。

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

属性值

集合中的当前元素。

示例

以下代码示例向包添加一个批量插入任务,检索Executables集合,创建枚举器,并使用。TaskHost

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

namespace Executables_API  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // Create the package and add the BulkInsertTask.  
            Package pkg = new Package();  
            Executable exec = pkg.Executables.Add("STOCK:BulkInsertTask");  

            // Obtain the collection.  
            Executables pgkExecs = pkg.Executables;  

            //Create the Enumerator.  
            ExecutableEnumerator myEnumerator = pgkExecs.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            Executable myExec;  
            TaskHost myTH;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
            {  
                myExec = (Executable)myEnumerator.Current;  
                myTH = (TaskHost)myExec;  
                Console.WriteLine("[{0}] {1}", i++, myTH.Name);  
            }  
            // Reset puts the index pointer before the beginning.  
            // Do not retrieve from the collection until MoveNext is called.  
            myEnumerator.Reset();  
            myEnumerator.MoveNext();  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Executables_API  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            ' Create the package and add the BulkInsertTask.  
            Dim pkg As Package =  New Package()   
            Dim exec As Executable =  pkg.Executables.Add("STOCK:BulkInsertTask")   

            ' Obtain the collection.  
            Dim pgkExecs As Executables =  pkg.Executables   

            'Create the Enumerator.  
            Dim myEnumerator As ExecutableEnumerator =  pgkExecs.GetEnumerator()   
            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            Dim myExec As Executable  
            Dim myTH As TaskHost  
            While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)  
                myExec = CType(myEnumerator.Current, Executable)  
                myTH = CType(myExec, TaskHost)  
                Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1  
            End While  
            ' Reset puts the index pointer before the beginning.  
            ' Do not retrieve from the collection until MoveNext is called.  
            myEnumerator.Reset()  
            myEnumerator.MoveNext()  
         End Sub  
    End Class  
End Namespace  

示例输出:

该集合包含以下数值:

[0] {C435F0C7-97E8-4DCC-A0FF-C6C805D9F64E}

注解

在创建枚举子或调用 Reset 该方法后,必须调用该 MoveNext 方法将枚举子推进到集合的第一个元素,枚举器才能读取属性的 Current 值;否则, Current 为未定义并抛出异常。

Current 如果最后一次调用 MoveNext 返回 false,则也会引发异常,这表示集合的末尾。

Current不会移动枚举器的位置,并且连续调用以Current返回同一对象,直到调用或MoveNextReset调用。

只要集合保持不变,枚举器就保持有效。 如果对集合进行了更改,比如添加、修改或删除元素,枚举器将失效并无法恢复;因此,下一次调用 Or MoveNextReset 会抛出异常。 然而,如果集合在调用和MoveNextCurrent之间被修改,Current即使枚举器已被失效,集合返回了它所设定的元素。

适用于