ExtendedProperties.Contains(Object) 方法

定义

返回一个布尔值,该值指示是否可以使用索引访问集合中的项,而不引发异常。

public:
 bool Contains(System::Object ^ index);
public bool Contains (object index);
member this.Contains : obj -> bool
Public Function Contains (index As Object) As Boolean

参数

index
Object

要在集合中找到的名称、标识、ID 或索引。

返回

一个布尔值,指示是否可以按名称、说明、ID 或索引访问集合。 true 值指示可以使用语法 ExtendedProperties[index] 访问集合。 false 值指示索引不能用于从 ExtendedProperties 集合中检索项;使用此属性引发异常。

示例

下面的代码示例使用 Contains 方法来确定给定的 GUID 的扩展属性是否在集合中。 该方法返回一个 Boolean.

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;  

            // Use the ID.  
            Boolean hasGUID = myExtProps.Contains("{F3B7314E-DB1E-4CCA-A856-2E617A1B3265}");  
            Console.WriteLine("The extended property contains that GUID? {0}", hasGUID);  
            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   

            ' Use the ID.  
            Dim hasGUID As Boolean =  myExtProps.Contains("{F3B7314E-DB1E-4CCA-A856-2E617A1B3265}")   
            Console.WriteLine("The extended property contains that GUID? {0}", hasGUID)  
            Console.WriteLine()  
        End Sub  
    End Class  
End Namespace  

示例输出:

扩展属性包含该 GUID? True

适用于