Condividi tramite


ExecutableEnumerator.Current Proprietà

Definizione

Ottiene l'elemento corrente della raccolta.

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

Valore della proprietà

Elemento corrente nella raccolta.

Esempio

Nell'esempio di codice seguente viene aggiunta un'attività Inserimento bulk al pacchetto, viene recuperata la Executables raccolta, viene creato un enumeratore e viene visualizzato il nome usando .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  

Esempio di output

La raccolta contiene i valori seguenti:

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

Commenti

Dopo la creazione di un enumeratore o dopo una chiamata al Reset metodo , è necessario chiamare il MoveNext metodo per far avanzare l'enumeratore al primo elemento della raccolta prima che l'enumeratore possa leggere il valore della Current proprietà; in caso contrario, Current non è definito e genera un'eccezione.

Current genera anche un'eccezione se l'ultima chiamata a MoveNext restituisce false, che indica la fine della raccolta.

Current non sposta la posizione dell'enumeratore e le chiamate consecutive per restituire lo stesso oggetto fino a Current quando MoveNext non viene chiamato o Reset .

Un enumeratore rimane valido finché la raccolta rimane invariata. Se vengono apportate modifiche alla raccolta, ad esempio l'aggiunta, la modifica o l'eliminazione di elementi, l'enumeratore viene invalidato e diventa irrecuperabile; pertanto, la chiamata successiva a MoveNext o Reset genera un'eccezione. Tuttavia, se la raccolta viene modificata tra le chiamate a MoveNext e Current, Current restituisce l'elemento su cui è impostato, anche se l'enumeratore è stato invalidato.

Si applica a