ExtendedPropertyEnumerator.Current 属性

定义

从集合返回当前的 ExtendedProperty 对象。

public:
 property Microsoft::SqlServer::Dts::Runtime::ExtendedProperty ^ Current { Microsoft::SqlServer::Dts::Runtime::ExtendedProperty ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.ExtendedProperty Current { get; }
member this.Current : Microsoft.SqlServer.Dts.Runtime.ExtendedProperty
Public ReadOnly Property Current As ExtendedProperty

属性值

当前的 ExtendedProperty 对象。

示例

下面的代码示例创建一个枚举器,然后使用 Current MoveNext 方法在集合上导航。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
namespace ExtendedProperties_Testing  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // The package is one of the SSIS Samples.  
            string mySample = @"C:\Program Files\Microsoft SQL Server\100\Tools\Samples\1033\DataTransformationServices\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx";  
            // Create the Application, and load the sample.  
            Application app = new Application();  
            Package pkg = app.LoadPackage(mySample, null);  

            // Get the Extended properties collection from the package.  
            ExtendedProperties myExtProps = pkg.ExtendedProperties;  
            //Create the Enumerator.  
            ExtendedPropertyEnumerator myEnumerator = myExtProps.GetEnumerator();  

            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            ExtendedProperty myExtProp;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
            {  
                myExtProp = (ExtendedProperty)myEnumerator.Current;  
                Console.WriteLine("[{0}] {1}, {2}", i++, myExtProp.ID, myExtProp.DataType);  
                Console.WriteLine("------------------------------");  
            }  
            // Reset puts the index pointer before the beginning.  
            // Do not retrieve from the collection until MoveNext is called.  
            myEnumerator.Reset();  
            myEnumerator.MoveNext();  

            // Now that the enumerator has been reset, and moved to the  
            // first item in the collection, show the first item.  
            myExtProp = (ExtendedProperty)myEnumerator.Current;  
            Console.WriteLine("The first item in the enumerator after Reset:");  
            Console.WriteLine("{0}, {1}", myExtProp.ID, myExtProp.DataType);  
            Console.WriteLine();  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace ExtendedProperties_Testing  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            ' The package is one of the SSIS Samples.  
            Dim mySample As String =  "C:\Program Files\Microsoft SQL Server\100\Tools\Samples\1033\DataTransformationServices\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx"   
            ' Create the Application, and load the sample.  
            Dim app As Application =  New Application()   
            Dim pkg As Package =  app.LoadPackage(mySample,Nothing)   

            ' Get the Extended properties collection from the package.  
            Dim myExtProps As ExtendedProperties =  pkg.ExtendedProperties   
            'Create the Enumerator.  
            Dim myEnumerator As ExtendedPropertyEnumerator =  myExtProps.GetEnumerator()   

            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            Dim myExtProp As ExtendedProperty  
            While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)  
                myExtProp = CType(myEnumerator.Current, ExtendedProperty)  
                Console.WriteLine("[{0}] {1}, {2}",i = Console.WriteLine("[{0}] {1}, {2}",i + 1  
                Console.WriteLine("------------------------------")  
            End While  
            ' Reset puts the index pointer before the beginning.  
            ' Do not retrieve from the collection until MoveNext is called.  
            myEnumerator.Reset()  
            myEnumerator.MoveNext()  

            ' Now that the enumerator has been reset, and moved to the  
            ' first item in the collection, show the first item.  
            myExtProp = CType(myEnumerator.Current, ExtendedProperty)  
            Console.WriteLine("The first item in the enumerator after Reset:")  
            Console.WriteLine("{0}, {1}", myExtProp.ID, myExtProp.DataType)  
            Console.WriteLine()  
        End Sub  
    End Class  
End Namespace  

示例输出:

集合包含以下值:

[0] {F3B7314E-DB1E-4CCA-A856-2E617A1B3265}, 字符串

------------------------------

[1] {AA947F2D-C3B3-420F-B39E-4B7C77DAAFC0}, 字符串

------------------------------

[2] {AB2CCC33-3090-4C36-B444-5B50BB481324}, 字符串

------------------------------

[3] {FE85601C-4ECC-41D4-BEAA-1318DDF7EE2A}, 字符串

------------------------------

[4] {4D1641B9-94EF-4144-9820-1B30ABD2214F}, 字符串

------------------------------

[5] {4E76A01C-BFF8-462D-AAB0-FB48B3EEAE00}, 字符串

------------------------------

[6] {A56842E2-11C1-487E-B670-33F25B534146}, 字符串

------------------------------

重置后枚举器中的第一项:

{F3B7314E-DB1E-4CCA-A856-2E617A1B3265}, 字符串

注解

创建枚举器或调用 Reset 方法后,必须调用 MoveNext 方法才能将枚举器提升到集合的第一个元素,然后枚举器才能读取 Current 属性的值:否则, Current 未定义并引发异常。

如果返回falseMoveNext 的最后一次调用,则 Current 也会引发异常,该调用指示集合的末尾。

当前 不会移动枚举器的位置,并且对 Current 的连续调用将返回相同的对象,直到调用 MoveNextReset

只要集合保持不变,枚举器就仍有效。 如果对集合进行了更改(例如添加、修改或删除元素),则枚举器将失效并变为不可恢复;因此,对 MoveNextReset 的下一次调用将引发 InvalidOperationException。 如果在对 MoveNextCurrent 的调用之间修改了集合, 则 Current 将返回它设置为的元素,即使枚举器已失效。

适用于