ConfigurationEnumerator.Current 属性

定义

从集合获取当前的 Configuration 对象。

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

属性值

集合中的当前元素。

示例

下面的代码示例创建一个 ConfigurationEnumerator,然后循环访问集合,其中显示了配置名称。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace Configurations_API  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package p = new Package();  

            Configuration conf1 = p.Configurations.Add();  
            conf1.ConfigurationString = "Conf1 Configuration String";  
            conf1.ConfigurationType = DTSConfigurationType.EnvVariable;  
            conf1.Description = "Some description for Conf1 configuration";  
            conf1.Name = "Conf1";  
            conf1.PackagePath = "A Variable Name in configuration Conf1";  

            Configuration conf2 = p.Configurations.Add();  
            conf2.ConfigurationString = "Conf2 Configuration String";  
            conf2.ConfigurationType = DTSConfigurationType.ConfigFile;  
            conf2.Description = "Some description for Conf2 configuration";  
            conf2.Name = "Conf2";  
            conf2.PackagePath = "A Variable Name in configuration Conf2";  

            Configuration conf3 = p.Configurations.Add();  
            conf3.ConfigurationString = "Conf3 Configuration String2";  
            conf3.ConfigurationType = DTSConfigurationType.RegEntry;  
            conf3.Description = "Conf3 description for Conf3 configuration2";  
            conf3.Name = "Conf3";  
            conf3.PackagePath = "A Variable Name in configuration Conf3";  

            Configurations pkgConfigs = p.Configurations;  
            ConfigurationEnumerator myEnumerator = pkgConfigs.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
                Console.WriteLine("[{0}] {1}", i++, myEnumerator.Current.Name);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Configurations_API  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim p As Package =  New Package()   

            Dim conf1 As Configuration =  p.Configurations.Add()   
            conf1.ConfigurationString = "Conf1 Configuration String"  
            conf1.ConfigurationType = DTSConfigurationType.EnvVariable  
            conf1.Description = "Some description for Conf1 configuration"  
            conf1.Name = "Conf1"  
            conf1.PackagePath = "A Variable Name in configuration Conf1"  

            Dim conf2 As Configuration =  p.Configurations.Add()   
            conf2.ConfigurationString = "Conf2 Configuration String"  
            conf2.ConfigurationType = DTSConfigurationType.ConfigFile  
            conf2.Description = "Some description for Conf2 configuration"  
            conf2.Name = "Conf2"  
            conf2.PackagePath = "A Variable Name in configuration Conf2"  

            Dim conf3 As Configuration = p.Configurations.Add()   
            conf3.ConfigurationString = "Conf3 Configuration String2"  
            conf3.ConfigurationType = DTSConfigurationType.RegEnTry  
            conf3.Description = "Conf3 description for Conf3 configuration2"  
            conf3.Name = "Conf3"  
            conf3.PackagePath = "A Variable Name in configuration Conf3"  

            Dim pkgConfigs As Configurations = p.Configurations   
            Dim myEnumerator As ConfigurationEnumerator =  pkgConfigs.GetEnumerator()   
            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)  
            Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1  
            End While  
        End Sub  
    End Class  
End Namespace  

示例输出:

集合包含以下值:

[0] Conf1

[1] Conf2

[2] Conf3

注解

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

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

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

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

适用于