ExtendedPropertyEnumerator.Current Property


Returns the current ExtendedProperty object from the collection.

Namespace:   Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

public ExtendedProperty Current { get; }

After an enumerator is created, or after a call to the Reset method, the MoveNext method must be called to advance the enumerator to the first element of the collection before the enumerator can read the value of the Current property; otherwise, Current is undefined and throws an exception.

Current also throws an exception if the last call to MoveNext returned false, which indicates the end of the collection.

Current does not move the position of the enumerator, and consecutive calls to Current return the same object until either MoveNext or Reset is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is invalidated and becomes irrecoverable; thus, the next call to MoveNext or Reset throws an InvalidOperationException. If the collection is modified between calls to MoveNext and Current, Current returns the element that it is set to, even if the enumerator has been invalidated.

The following code sample creates an enumerator, and then uses the Current and MoveNext methods to navigate over the collection.

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);
            // Reset puts the index pointer before the beginning.
            // Do not retrieve from the collection until MoveNext is called.

            // 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);

Sample Output:

The collection contains the following values:

[0] {F3B7314E-DB1E-4CCA-A856-2E617A1B3265}, String


[1] {AA947F2D-C3B3-420F-B39E-4B7C77DAAFC0}, String


[2] {AB2CCC33-3090-4C36-B444-5B50BB481324}, String


[3] {FE85601C-4ECC-41D4-BEAA-1318DDF7EE2A}, String


[4] {4D1641B9-94EF-4144-9820-1B30ABD2214F}, String


[5] {4E76A01C-BFF8-462D-AAB0-FB48B3EEAE00}, String


[6] {A56842E2-11C1-487E-B670-33F25B534146}, String


The first item in the enumerator after Reset:

{F3B7314E-DB1E-4CCA-A856-2E617A1B3265}, String

Return to top