共用方式為


ExecutableEnumerator.Current Property

Gets the current element in the collection.

命名空間: Microsoft.SqlServer.Dts.Runtime
組件: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)

語法

'宣告
Public ReadOnly Property Current As Executable
public Executable Current { get; }
public:
property Executable^ Current {
    Executable^ get ();
}
/** @property */
public Executable get_Current ()
public function get Current () : Executable

屬性值

The current element in the collection.

備註

After an enumerator is created, or after a call to the Reset method, the MoveNext method must be called to advance the enumerator to the first element of the collection before the enumerator can read the value of the Current property; otherwise, Current is undefined and throws an exception.

Current also throws an exception if the last call to MoveNext returned false, which indicates the end of the collection.

Current does not move the position of the enumerator, and consecutive calls to Current return the same object until either MoveNext or Reset is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is invalidated and becomes irrecoverable; thus, the next call to MoveNext or Reset throws an exception. However, if the collection is modified between calls to MoveNext and Current, Current returns the element that it is set to, even if the enumerator has been invalidated.

範例

The following code example adds a Bulk Insert task to the package, retrieves the Executables collection, creates an enumerator, and shows the name using the 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

Sample Output:

The collection contains the following values:

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

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

平台

開發平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

目標平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

請參閱

參考

ExecutableEnumerator Class
ExecutableEnumerator Members
Microsoft.SqlServer.Dts.Runtime Namespace