InstallerCollection.Contains(Installer) 方法

定义

确定指定的安装程序是否包含在集合中。

public:
 bool Contains(System::Configuration::Install::Installer ^ value);
public bool Contains (System.Configuration.Install.Installer value);
member this.Contains : System.Configuration.Install.Installer -> bool
Public Function Contains (value As Installer) As Boolean

参数

value
Installer

一个 Installer,它代表要查找的安装程序。

返回

如果指定的安装程序在此集合中,则为 true;否则为 false

示例

下面的示例演示 类的 Remove 方法、 Contains 方法和 IndexOf 方法 InstallerCollection 。 它为 MyAssembly1.exeMyAssembly2.exe创建AssemblyInstaller实例。 这些实例将添加到 。TransactedInstaller MyAssembly2.exe 然后从 InstallerCollectionTransactedInstaller中删除 。 安装过程将启动并仅 MyAssembly1.exe安装 。

TransactedInstaller^ myTransactedInstaller = gcnew TransactedInstaller;
AssemblyInstaller^ myAssemblyInstaller1;
AssemblyInstaller^ myAssemblyInstaller2;
InstallContext^ myInstallContext;

// Create a instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
myAssemblyInstaller1 = gcnew AssemblyInstaller( "MyAssembly1.exe",nullptr );

// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller->Installers->Insert( 0, myAssemblyInstaller1 );

// Create a instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
myAssemblyInstaller2 = gcnew AssemblyInstaller( "MyAssembly2.exe",nullptr );

// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller->Installers->Insert( 1, myAssemblyInstaller2 );

// Remove the 'myAssemblyInstaller2' from the 'Installers' collection.
if ( myTransactedInstaller->Installers->Contains( myAssemblyInstaller2 ) )
{
   Console::WriteLine( "\nInstaller at index : {0} is being removed", myTransactedInstaller->Installers->IndexOf( myAssemblyInstaller2 ) );
   myTransactedInstaller->Installers->Remove( myAssemblyInstaller2 );
}
TransactedInstaller myTransactedInstaller = new TransactedInstaller();
AssemblyInstaller myAssemblyInstaller1;
AssemblyInstaller myAssemblyInstaller2;
InstallContext myInstallContext;

// Create a instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
myAssemblyInstaller1 =
   new AssemblyInstaller("MyAssembly1.exe", null);

// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Insert(0, myAssemblyInstaller1);

// Create a instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
myAssemblyInstaller2 =
   new AssemblyInstaller("MyAssembly2.exe", null);

// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Insert(1, myAssemblyInstaller2);

// Remove the 'myAssemblyInstaller2' from the 'Installers' collection.
if(myTransactedInstaller.Installers.Contains(myAssemblyInstaller2))
{
   Console.WriteLine("\nInstaller at index : {0} is being removed",
      myTransactedInstaller.Installers.IndexOf(myAssemblyInstaller2));
   myTransactedInstaller.Installers.Remove(myAssemblyInstaller2);
}
Dim myTransactedInstaller As New TransactedInstaller()
Dim myAssemblyInstaller1 As AssemblyInstaller
Dim myAssemblyInstaller2 As AssemblyInstaller
Dim myInstallContext As InstallContext

' Create a instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
myAssemblyInstaller1 = New AssemblyInstaller("MyAssembly1.exe", Nothing)

' Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Insert(0, myAssemblyInstaller1)

' Create a instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
myAssemblyInstaller2 = New AssemblyInstaller("MyAssembly2.exe", Nothing)

' Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Insert(1, myAssemblyInstaller2)

' Remove the 'myAssemblyInstaller2' from the 'Installers' collection.
If myTransactedInstaller.Installers.Contains(myAssemblyInstaller2) Then
   Console.WriteLine(ControlChars.Newline + "Installer at index : {0} is being removed", _
                     myTransactedInstaller.Installers.IndexOf(myAssemblyInstaller2))
   myTransactedInstaller.Installers.Remove(myAssemblyInstaller2)
End If

适用于

另请参阅