语言

DtsProperties.Contains(Object) 方法

定义

返回一个布尔值,指示集合中的元素是否可以通过对象的 DtsProperty 名称、身份或索引访问。

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

对象的 DtsProperty 名称、身份或索引。

返回

一个布尔值,表示集合是否可以通过名称、身份或索引访问。 为真的值表示可以通过语法 DtsProperties[index] 访问该集合。 值为false表示索引无法用于从集合中检索项目 DtsProperties

示例

以下代码示例使用该 Contains 方法来判断集合中的某个属性是否为“CertificateObject”。

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

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

            // Get the Properties collection from the package.  
            // This shows the default properties set on new packages.  
            DtsProperties pkgProperties = pkg.Properties;  

           // Create the enumerator.  
            PropertyEnumerator myEnumerator = pkgProperties.GetEnumerator();  

            // Show the use of the Contains method.  
            Boolean containsCertObj = pkgProperties.Contains("CertificateObject");  
            Console.WriteLine("Contains CertificateObject? {0}", containsCertObj);  

            // Show the use of the item[x] syntax.  
            String aName = pkgProperties[5].Name;  
            Console.WriteLine("Property 5 is {0}", aName);  

            // Show the use of the MoveNext and Current methods.  
            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 DtsProperties_API  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   

            ' Get the Properties collection from the package.  
            ' This shows the default properties set on new packages.  
            Dim pkgProperties As DtsProperties =  pkg.Properties   

           ' Create the enumerator.  
            Dim myEnumerator As PropertyEnumerator =  pkgProperties.GetEnumerator()   

            ' Show the use of the Contains method.  
            Dim containsCertObj As Boolean =  pkgProperties.Contains("CertificateObject")   
            Console.WriteLine("Contains CertificateObject? {0}", containsCertObj)  

            ' Show the use of the item[x] syntax.  
            Dim aName As String =  pkgProperties(5).Name   
            Console.WriteLine("Property 5 is {0}", aName)  

            ' Show the use of the MoveNext and Current methods.  
            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  

示例输出:

包含CertificateObject? 是

性质5是配置

[0] 证书上下文

[1] 证书对象

[2] 检查点文件名

[3] 检查点使用

[4] CheckSignatureOnLoad

[5] 配置

[6] 连接

[7] 创作日期

[8] 创世名

[9] 创造者计算机名

[10] 创作者名

[11] 延迟验证

。 。 。

[63] 版本指南

[64] 版本大

[65] 版本次要

[66] 警告

适用于