Configurations.Contains(Object) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne une valeur booléenne qui indique si les éléments de la collection sont accessibles par un index sans lever d’exception.
public:
bool Contains(System::Object ^ index);
public bool Contains (object index);
member this.Contains : obj -> bool
Public Function Contains (index As Object) As Boolean
Paramètres
- index
- Object
Nom, identité, ID ou index de l'objet Configuration à trouver dans la collection.
Retours
Valeur booléenne qui indique si la collection est accessible par nom, identité, ID ou index. La valeur true indique que la collection est accessible à l’aide de la syntaxe Configurations[index]. La valeur false indique que l’indexation ne peut pas être utilisée pour récupérer des éléments de la Configurations collection . L’utilisation de cette propriété lève une exception.
Exemples
L’exemple de code suivant utilise la méthode pour voir si la Contains syntaxe de l’élément est disponible.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
namespace Configurations_API
{
class Program
{
static void Main(string[] args)
{
Package p = new Package();
Configuration conf1 = p.Configurations.Add();
conf1.ConfigurationString = "Conf1 Configuration String";
conf1.ConfigurationType = DTSConfigurationType.EnvVariable;
conf1.Description = "Some description for Conf1 configuration";
conf1.Name = "Conf1";
conf1.PackagePath = "A Variable Name in configuration Conf1";
Configuration conf2 = p.Configurations.Add();
conf2.ConfigurationString = "Conf2 Configuration String";
conf2.ConfigurationType = DTSConfigurationType.ConfigFile;
conf2.Description = "Some description for Conf2 configuration";
conf2.Name = "Conf2";
conf2.PackagePath = "A Variable Name in configuration Conf2";
Configuration conf3 = p.Configurations.Add();
conf3.ConfigurationString = "Conf3 Configuration String2";
conf3.ConfigurationType = DTSConfigurationType.RegEntry;
conf3.Description = "Conf3 description for Conf3 configuration2";
conf3.Name = "Conf3";
conf3.PackagePath = "A Variable Name in configuration Conf3";
// Use Contains to see if item syntax is available.
Boolean configContains = p.Configurations.Contains("Conf3");
if (configContains)
{
// Use the item syntax of Configurations[x].
String myName = p.Configurations[0].Name;
Console.WriteLine("Name of configuration at position 0 is {0}", myName);
}
else
{
Console.WriteLine("Contains returned {0}", configContains);
}
Console.WriteLine();
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Namespace Configurations_API
Class Program
Shared Sub Main(ByVal args() As String)
Dim p As Package = New Package()
Dim conf1 As Configuration = p.Configurations.Add()
conf1.ConfigurationString = "Conf1 Configuration String"
conf1.ConfigurationType = DTSConfigurationType.EnvVariable
conf1.Description = "Some description for Conf1 configuration"
conf1.Name = "Conf1"
conf1.PackagePath = "A Variable Name in configuration Conf1"
Dim conf2 As Configuration = p.Configurations.Add()
conf2.ConfigurationString = "Conf2 Configuration String"
conf2.ConfigurationType = DTSConfigurationType.ConfigFile
conf2.Description = "Some description for Conf2 configuration"
conf2.Name = "Conf2"
conf2.PackagePath = "A Variable Name in configuration Conf2"
Dim conf3 As Configuration = p.Configurations.Add()
conf3.ConfigurationString = "Conf3 Configuration String2"
conf3.ConfigurationType = DTSConfigurationType.RegEnTry
conf3.Description = "Conf3 description for Conf3 configuration2"
conf3.Name = "Conf3"
conf3.PackagePath = "A Variable Name in configuration Conf3"
' Use Contains to see if item syntax is available.
Dim configContains As Boolean = p.Configurations.Contains("Conf3")
If configContains = True Then
' Use the item syntax of Configurations[x].
Dim myName As String = p.Configurations(0).Name
Console.WriteLine("Name of configuration at position 0 is {0}", myName)
Else
Console.WriteLine("Contains returned {0}", configContains)
End If
Console.WriteLine()
End Sub
End Class
End Namespace
Exemple de sortie :
Nom de la configuration à la position 0 est Conf1