ExecutableEnumerator.Current Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan elemen saat ini dalam koleksi.
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
Nilai Properti
Elemen saat ini dalam koleksi.
Contoh
Contoh kode berikut menambahkan tugas Sisipkan Massal ke paket, mengambil Executables koleksi, membuat enumerator, dan memperlihatkan nama menggunakan 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
Contoh Output:
Koleksi berisi nilai berikut:
[0] {C435F0C7-97E8-4DCC-A0FF-C6c805d9F64E}
Keterangan
Setelah enumerator dibuat, atau setelah panggilan ke Reset metode , MoveNext metode harus dipanggil untuk memajukan enumerator ke elemen pertama koleksi sebelum enumerator dapat membaca nilai Current properti; jika tidak, Current tidak terdefinisi dan melempar pengecualian.
Current juga melemparkan pengecualian jika panggilan terakhir untuk MoveNext dikembalikan false, yang menunjukkan akhir koleksi.
Current tidak memindahkan posisi enumerator, dan panggilan berturut-turut untuk Current mengembalikan objek yang sama hingga atau MoveNextReset dipanggil.
Enumerator tetap valid selama koleksi tetap tidak berubah. Jika perubahan dilakukan pada koleksi, seperti menambahkan, memodifikasi, atau menghapus elemen, enumerator tidak valid dan menjadi tidak dapat dipulihkan; dengan demikian, panggilan berikutnya ke MoveNext atau Reset melempar pengecualian. Namun, jika koleksi dimodifikasi antara panggilan ke MoveNext dan Current, Current mengembalikan elemen yang diatur ke, bahkan jika enumerator telah dibatalkan.