Share via


ExecutableEnumerator.Current Propiedad

Definición

Obtiene el elemento actual de la colección.

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

Valor de propiedad

Elemento actual de la colección.

Ejemplos

En el ejemplo de código siguiente se agrega una tarea Inserción masiva al paquete, se recupera la Executables colección, se crea un enumerador y se muestra el nombre mediante 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  

Salida del ejemplo:

La colección contiene los siguientes valores:

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

Comentarios

Después de crear un enumerador, o después de una llamada al Reset método , MoveNext se debe llamar al método para avanzar el enumerador al primer elemento de la colección antes de que el enumerador pueda leer el valor de la Current propiedad; de lo contrario, Current es indefinido y produce una excepción.

Currenttambién produce una excepción si se devuelve falsela última llamada a MoveNext , que indica el final de la colección.

Current no mueve la posición del enumerador y las llamadas consecutivas para Current devolver el mismo objeto hasta que MoveNext se llama a o Reset .

Un enumerador sigue siendo válido mientras la colección permanezca inalterada. Si se realizan cambios en la colección, como agregar, modificar o eliminar elementos, el enumerador se invalida y se convierte en irrecuperable; por lo tanto, la siguiente llamada a MoveNext o Reset produce una excepción. Sin embargo, si la colección se modifica entre llamadas a MoveNext y Current, Current devuelve el elemento en el que está establecido, incluso si el enumerador se ha invalidado.

Se aplica a