ExtendedPropertyEnumerator.Current 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從集合中傳回目前的 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會是未定義的,而且會擲回例外狀況。
如果最後一次呼叫MoveNext傳回,則Current也會擲回例外狀況 false ,指出集合的結尾。
Current不會移動列舉值的位置,而對目前的連續呼叫會傳回相同的物件,直到呼叫MoveNext或Reset為止。
只要集合維持不變,列舉值就仍維持有效。 如果對集合進行了變更,例如加入、修改或刪除專案,枚舉器會失效,且會變得無法復原。因此,下一次呼叫MoveNext或Reset時,會擲回InvalidOperationException。 如果在對MoveNext和Current的呼叫之間修改集合, Current會傳回其設定的專案,即使列舉值已經無效。