InstallerCollection.CopyTo(Installer[], Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從指定的索引開始,將集合中的項目複製到陣列。
public:
void CopyTo(cli::array <System::Configuration::Install::Installer ^> ^ array, int index);
public void CopyTo (System.Configuration.Install.Installer[] array, int index);
member this.CopyTo : System.Configuration.Install.Installer[] * int -> unit
Public Sub CopyTo (array As Installer(), index As Integer)
參數
- array
- Installer[]
要複製到其中的陣列。
- index
- Int32
要貼上集合的陣列索引。
範例
下列範例示範 CopyTo 類別的 InstallerCollection 方法。 它會建立 AssemblyInstaller 和MyAssembly2.exe
的MyAssembly1.exe
實例。 這些實體會新增至 TransactedInstaller。 要安裝的元件名稱會顯示在控制臺上。 安裝程式會同時 MyAssembly1.exe
安裝 和 MyAssembly2.exe
。
TransactedInstaller^ myTransactedInstaller = gcnew TransactedInstaller;
AssemblyInstaller^ myAssemblyInstaller;
InstallContext^ myInstallContext;
// Create an instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
myAssemblyInstaller =
gcnew AssemblyInstaller( "MyAssembly1.exe",nullptr );
// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller->Installers->Add( myAssemblyInstaller );
// Create an instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
myAssemblyInstaller =
gcnew AssemblyInstaller( "MyAssembly2.exe",nullptr );
// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller->Installers->Add( myAssemblyInstaller );
array<Installer^>^ myInstallers =
gcnew array<Installer^>(myTransactedInstaller->Installers->Count);
myTransactedInstaller->Installers->CopyTo( myInstallers, 0 );
// Print the assemblies to be installed.
Console::WriteLine( "Printing all assemblies to be installed -" );
for ( int i = 0; i < myInstallers->Length; i++ )
{
if ( dynamic_cast<AssemblyInstaller^>( myInstallers[ i ] ) )
{
Console::WriteLine( "{0} {1}", i + 1, ( (AssemblyInstaller^)( myInstallers[ i ]) )->Path );
}
}
TransactedInstaller myTransactedInstaller = new TransactedInstaller();
AssemblyInstaller myAssemblyInstaller;
InstallContext myInstallContext;
// Create an instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
myAssemblyInstaller =
new AssemblyInstaller("MyAssembly1.exe", null);
// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Add(myAssemblyInstaller);
// Create an instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
myAssemblyInstaller =
new AssemblyInstaller("MyAssembly2.exe", null);
// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Add(myAssemblyInstaller);
Installer[] myInstallers =
new Installer[myTransactedInstaller.Installers.Count];
myTransactedInstaller.Installers.CopyTo(myInstallers, 0);
// Print the assemblies to be installed.
Console.WriteLine("Printing all assemblies to be installed -");
for(int i = 0; i < myInstallers.Length; i++)
{
if((myInstallers[i].GetType()).Equals(typeof(AssemblyInstaller)))
{
Console.WriteLine("{0} {1}", i + 1,
((AssemblyInstaller)myInstallers[i]).Path);
}
}
Dim myTransactedInstaller As New TransactedInstaller()
Dim myAssemblyInstaller As AssemblyInstaller
Dim myInstallContext As InstallContext
' Create an instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
myAssemblyInstaller = New AssemblyInstaller("MyAssembly1.exe", Nothing)
' Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Add(myAssemblyInstaller)
' Create an instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
myAssemblyInstaller = New AssemblyInstaller("MyAssembly2.exe", Nothing)
' Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Add(myAssemblyInstaller)
Dim myInstallers(myTransactedInstaller.Installers.Count-1) As Installer
myTransactedInstaller.Installers.CopyTo(myInstallers, 0)
' Print the assemblies to be installed.
Console.WriteLine("Printing all assemblies to be installed -")
Dim i As Integer
For i = 0 To myInstallers.Length - 1
If myInstallers(i).GetType().Equals(GetType(AssemblyInstaller)) Then
Console.WriteLine("{0} {1}", i + 1, CType(myInstallers(i), AssemblyInstaller).Path)
End If
Next i