Freigeben über


FaultBindingCollection.Insert(Int32, FaultBinding) Methode

Definition

Fügt der FaultBinding die angegebene FaultBindingCollection am angegebenen nullbasierten Index hinzu.

public:
 void Insert(int index, System::Web::Services::Description::FaultBinding ^ bindingOperationFault);
public void Insert (int index, System.Web.Services.Description.FaultBinding bindingOperationFault);
member this.Insert : int * System.Web.Services.Description.FaultBinding -> unit
Public Sub Insert (index As Integer, bindingOperationFault As FaultBinding)

Parameter

index
Int32

Der nullbasierte Index, an dem der bindingOperationFault-Parameter eingefügt werden soll.

bindingOperationFault
FaultBinding

Der der Auflistung hinzuzufügende FaultBinding.

Beispiele

Im folgenden Beispiel wird eine typische Verwendung der Insert -Methode veranschaulicht.

BindingCollection^ myBindingCollection = myServiceDescription->Bindings;
Binding^ myBinding = myBindingCollection[ 0 ];
OperationBindingCollection^ myOperationBindingCollection = myBinding->Operations;
OperationBinding^ myOperationBinding = myOperationBindingCollection[ 0 ];
FaultBindingCollection^ myFaultBindingCollection = myOperationBinding->Faults;

// Reverse the fault bindings order.
if ( myFaultBindingCollection->Count > 1 )
{
   FaultBinding^ myFaultBinding = myFaultBindingCollection[ 0 ];
   array<FaultBinding^>^myFaultBindingArray = gcnew array<FaultBinding^>(myFaultBindingCollection->Count);
   
   // Copy the fault bindings to a temporary array.
   myFaultBindingCollection->CopyTo( myFaultBindingArray, 0 );
   
   // Remove all the fault binding instances in the fault binding collection.
   for ( int i = 0; i < myFaultBindingArray->Length; i++ )
      myFaultBindingCollection->Remove( myFaultBindingArray[ i ] );
   
   // Insert the fault binding instance in the reverse order.
   for ( int i = 0,j = (myFaultBindingArray->Length - 1); i < myFaultBindingArray->Length; i++,j-- )
      myFaultBindingCollection->Insert( i, myFaultBindingArray[ j ] );
   
   // Check if the first element in the collection before the reversal is now the last element.
   if ( myFaultBindingCollection->Contains( myFaultBinding ) && myFaultBindingCollection->IndexOf( myFaultBinding ) == (myFaultBindingCollection->Count - 1) )
         
   // Display the WSDL generated to the console.
   myServiceDescription->Write( Console::Out );
   else
         Console::WriteLine( "Error while reversing" );
}

BindingCollection myBindingCollection = myServiceDescription.Bindings;
Binding myBinding = myBindingCollection[0];
OperationBindingCollection myOperationBindingCollection = myBinding.Operations;
OperationBinding myOperationBinding = myOperationBindingCollection[0];
FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults;

// Reverse the fault bindings order.
if(myFaultBindingCollection.Count > 1)
{
   FaultBinding myFaultBinding = myFaultBindingCollection[0];

   FaultBinding[] myFaultBindingArray = new FaultBinding[myFaultBindingCollection.Count];
   // Copy the fault bindings to a temporary array.
   myFaultBindingCollection.CopyTo(myFaultBindingArray, 0);

   // Remove all the fault binding instances in the fault binding collection.
   for(int i = 0; i < myFaultBindingArray.Length; i++)
      myFaultBindingCollection.Remove(myFaultBindingArray[i]);

   // Insert the fault binding instance in the reverse order.
   for(int i = 0, j = (myFaultBindingArray.Length - 1); i < myFaultBindingArray.Length; i++, j--)
      myFaultBindingCollection.Insert(i, myFaultBindingArray[j]);
   // Check if the first element in the collection before the reversal is now the last element.
   if(myFaultBindingCollection.Contains(myFaultBinding) &&
      myFaultBindingCollection.IndexOf(myFaultBinding) == (myFaultBindingCollection.Count - 1))
      // Display the WSDL generated to the console.
      myServiceDescription.Write(Console.Out);
   else
      Console.WriteLine("Error while reversing");
}
      Dim myBindingCollection As BindingCollection = myServiceDescription.Bindings
      Dim myBinding As Binding = myBindingCollection(0)
      Dim myOperationBindingCollection As OperationBindingCollection = myBinding.Operations
      Dim myOperationBinding As OperationBinding = myOperationBindingCollection(0)
      Dim myFaultBindingCollection As FaultBindingCollection = myOperationBinding.Faults

      ' Reverse the fault bindings order.
      If myFaultBindingCollection.Count > 1 Then
         Dim myFaultBinding As FaultBinding = myFaultBindingCollection(0)

         Dim myFaultBindingArray(myFaultBindingCollection.Count - 1) As FaultBinding
         ' Copy the fault bindings to a temporary array.
         myFaultBindingCollection.CopyTo(myFaultBindingArray, 0)

         ' Remove all the fault binding instances in the fault binding collection.
         Dim i, j As Integer

         For i = 0 To myFaultBindingArray.Length - 1
            myFaultBindingCollection.Remove(myFaultBindingArray(i))
         Next i

         j = myFaultBindingArray.Length - 1
         For i = 0 To myFaultBindingArray.Length - 1
            myFaultBindingCollection.Insert(i, myFaultBindingArray(j))
            j = j - 1
         Next

         If myFaultBindingCollection.Contains(myFaultBinding) And myFaultBindingCollection.IndexOf(myFaultBinding) = myFaultBindingCollection.Count - 1 Then
            ' Display the WSDL generated to the console.
            myServiceDescription.Write(Console.Out)
         Else
            Console.WriteLine("Error while reversing")
         End If
      End If
   End Sub

End Class

Hinweise

Wenn die Anzahl der Elemente in der Auflistung bereits der Kapazität der Auflistung entspricht, wird die Kapazität verdoppelt, indem das interne Array automatisch neu zugewiesen wird, bevor das neue Element eingefügt wird.

Wenn der index Parameter gleich Countist, wird der bindingOperationFault -Parameter am Ende von FaultBindingCollectionhinzugefügt.

Die Elemente nach der Einfügemarke werden nach unten verschoben, um das neue Element aufzunehmen.

Gilt für: