次の方法で共有


ExecutableEnumerator.Current プロパティ

コレクション内にある現在の要素を取得します。

名前空間:  Microsoft.SqlServer.Dts.Runtime
アセンブリ:  Microsoft.SqlServer.ManagedDTS (Microsoft.SqlServer.ManagedDTS.dll)

構文

'宣言
Public ReadOnly Property Current As Executable 
    Get
'使用
Dim instance As ExecutableEnumerator 
Dim value As Executable 

value = instance.Current
public Executable Current { get; }
public:
property Executable^ Current {
    Executable^ get ();
}
member Current : Executable
function get Current () : Executable

プロパティ値

型: Microsoft.SqlServer.Dts.Runtime.Executable
コレクション内にある現在の要素です。

説明

列挙子を作成した後や Reset メソッドを呼び出した後は、Current プロパティの値を列挙子が読み取る前に、MoveNext メソッドを呼び出して列挙子をコレクションの先頭の要素に進めておく必要があります。そうしないと、Current は未定義となり、例外がスローされます。

前回の MoveNext の呼び出しで false が返された場合 (コレクションの末尾であることを示します)、その後で Current を呼び出しても例外がスローされます。

Current は列挙子の位置を移動しません。Current を連続して呼び出すと、MoveNext または Reset が呼び出されるまで同じオブジェクトが返されます。

列挙子は、コレクションが変更されない限り有効です。 要素の追加、変更、削除など、コレクションに変更が加えられた場合は、列挙子は無効になり回復できなくなります。そのため、次の MoveNext または Reset の呼び出しで例外がスローされます。 ただし、MoveNext を呼び出してから Current を呼び出すまでの間にコレクションが変更された場合、列挙子は無効になっていても、Current は設定されている要素を返します。

使用例

次のコード例では、一括挿入タスクをパッケージに追加してから 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

サンプルの出力 :

The collection contains the following values:

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

関連項目

参照

ExecutableEnumerator クラス

Microsoft.SqlServer.Dts.Runtime 名前空間