次の方法で共有


VariableDispenser.Contains(String) メソッド

定義

例外がスローされることなく、インデックスを使用して VariableDispenser コレクションから項目を取得できるかどうかを指定します。

public:
 bool Contains(System::String ^ variable);
public bool Contains (string variable);
member this.Contains : string -> bool
Public Function Contains (variable As String) As Boolean

パラメーター

variable
String

VariableDispenser コレクション内で検索する変数の名前です。

戻り値

true は、例外をスローせずに VariableDispenser[x] 構文を使用できることを示します。 false の値は、インデックス作成を使用してコレクションから項目を取得できないことを示します。

次のコード例では、VariableDispenser を作成し、Contains メソッドを使用して、コレクションでインデックス構文を使用できるかどうかを示す Boolean を返します。

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

namespace Microsoft.SqlServer.SSIS.Sample  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            Variables vars = null;  
            VariableDispenser variableDispenser = pkg.VariableDispenser;  
            variableDispenser.LockForRead("System::PackageName");  
            variableDispenser.LockForRead("System::OfflineMode");  
            variableDispenser.GetVariables(ref vars);             
            // Verify that the variable is locked before unlocking.  
            Console.WriteLine("Variables are locked? {0}", vars.Locked);  
            foreach (Variable myVar in vars)  
            {  
                Console.WriteLine("Name        {0}", myVar.Name);  
                Console.WriteLine("Description {0}", myVar.Description);  
                Console.WriteLine();  
            }  
            // Use Contains to determine whether indexing can be used.  
            Boolean pkgName = variableDispenser.Contains("PackageName");  
            String qName = variableDispenser.GetQualifiedName("PackageName");  
            Console.WriteLine("Contains is valid?       {0}", pkgName);  
            Console.WriteLine("Fully qualified name is: {0}", qName);  

            vars.Unlock();  

            Console.WriteLine("Variables are locked? {0}", vars.Locked);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Microsoft.SqlServer.SSIS.Sample  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   
            Dim vars As Variables =  Nothing   
            Dim variableDispenser As VariableDispenser =  pkg.VariableDispenser   
            variableDispenser.LockForRead("System::PackageName")  
            variableDispenser.LockForRead("System::OfflineMode")  
            variableDispenser.GetVariables( vars)  
            ' Verify that the variable is locked before unlocking.  
            Console.WriteLine("Variables are locked? {0}", vars.Locked)  
            Dim myVar As Variable  
            For Each myVar In vars  
                Console.WriteLine("Name        {0}", myVar.Name)  
                Console.WriteLine("Description {0}", myVar.Description)  
                Console.WriteLine()  
            Next  
            ' Use Contains to determine whether indexing can be used.  
            Dim pkgName As Boolean =  variableDispenser.Contains("PackageName")   
            Dim qName As String =  variableDispenser.GetQualifiedName("PackageName")   
            Console.WriteLine("Contains is valid?       {0}", pkgName)  
            Console.WriteLine("Fully qualified name is: {0}", qName)  

            vars.Unlock()  

            Console.WriteLine("Variables are locked? {0}", vars.Locked)  
        End Sub  
    End Class  
End Namespace  

サンプル出力:

Variables are locked? True

Name OfflineMode

Description The offline mode currently set for the package

Name PackageName

Description The package name

Contains is valid? True

Fully qualified name is: System::PackageName

Variables are locked? False

適用対象