Partager via


VariableDispenser.Contains(String) Méthode

Définition

Spécifie si un élément peut être récupéré de la collection VariableDispenser en utilisant l'indexation sans lever d'exception.

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

Paramètres

variable
String

Nom de la variable à trouver dans la collection VariableDispenser.

Retours

true indique que la syntaxe VariableDispenser[x] peut être utilisée sans lever d’exception. La valeur false indique que l’indexation ne peut pas être utilisée pour récupérer des éléments de la collection.

Exemples

L’exemple de code suivant crée une VariableDispenser méthode et utilise la Contains méthode pour retourner une Boolean valeur pour déterminer si la syntaxe d’indexation peut être utilisée sur la collection.

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  

Exemple de sortie :

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

S’applique à