语言

ExtendedProperties.Item[Object] 属性

定义

从集合中获取对象 ExtendedProperty 。

public:
 property Microsoft::SqlServer::Dts::Runtime::ExtendedProperty ^ default[System::Object ^] { Microsoft::SqlServer::Dts::Runtime::ExtendedProperty ^ get(System::Object ^ index); };
public Microsoft.SqlServer.Dts.Runtime.ExtendedProperty this[object index] { get; }
member this.Item(obj) : Microsoft.SqlServer.Dts.Runtime.ExtendedProperty
Default Public ReadOnly Property Item(index As Object) As ExtendedProperty

参数

index
Object

要返回对象的 ExtendedProperty 名称、描述、ID或索引。

属性值

收藏中的一件 ExtendedProperty 物品。

示例

以下代码示例通过两种方法从集合中检索一个项目。 第一种方法是利用语 myExtProps[0] 法检索集合中第一个位置的整个对象并将其放入对象 myExtProp 中。 你现在可以像往常一样从对象中检索所有属性 myExtProp 。 第二种方法演示了如何从集合中的第一个对象中检索特定属性 DataType。

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\Samples\Integration Services\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;  

            //Using the Item method syntax of [x], obtain the  
            // entire first entry, and then just the name.  
            ExtendedProperty myExtProp = myExtProps[0];  
            String dataTypeOfFirstItem = myExtProps[0].DataType.ToString();  

            //Print the name of the extended property   
           //located at position [0].  
            Console.WriteLine("The ID of the first item is: {0}", myExtProp.ID);  
            Console.WriteLine("The DataType of the first item is: {0}", dataTypeOfFirstItem);  
            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\Samples\Integration Services\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   

            'Using the Item method syntax of [x], obtain the  
            ' entire first entry, and then just the name.  
            Dim myExtProp As ExtendedProperty =  myExtProps(0)   
            Dim dataTypeOfFirstItem As String =  myExtProps(0).DataType.ToString()   

            'Print the name of the extended property   
           'located at position [0].  
            Console.WriteLine("The ID of the first item is: {0}", myExtProp.ID)  
            Console.WriteLine("The DataType of the first item is: {0}", dataTypeOfFirstItem)  
            Console.WriteLine()  
        End Sub  
    End Class  
End Namespace  

示例输出:

第一个项目的ID是:{F3B7314E-DB1E-4CCA-A856-2E617A1B3265}

第一个项目的数据类型是:String

注解

如果 Contains 调用方法返回 true,你可以通过语法 ExtendedProperties[index]访问集合中指定的元素。 然而,如果 Contains 方法返回 false,该性质会抛出异常。 在 C# 中,此属性是类的 ExtendedProperties 索引器。

适用于