ResourceReader.GetEnumerator Metoda

Definicja

Zwraca moduł wyliczający dla tego ResourceReader obiektu.

public:
 virtual System::Collections::IDictionaryEnumerator ^ GetEnumerator();
public:
 System::Collections::IDictionaryEnumerator ^ GetEnumerator();
public System.Collections.IDictionaryEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
override this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
member this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
Public Function GetEnumerator () As IDictionaryEnumerator

Zwraca

IDictionaryEnumerator

Moduł wyliczający dla tego ResourceReader obiektu.

Implementuje

Wyjątki

Czytelnik został zamknięty lub usunięty i nie można uzyskać dostępu.

Przykłady

W przykładzie w tej sekcji użyto następującego pliku .txt o nazwie w PatientForm.txt celu zdefiniowania zasobów używanych przez aplikację.

Title="Top Pet Animal Clinic"  
Label1="Patient Number:"  
Label2="Pet Name:"  
Label3="Species:"  
Label4="Breed:"  
Label5="Date of Birth:"  
Label6="Age:"  
Label7="Owner:"  
Label8="Address:"  
Label9="Home Phone:"  
Label10="Work Phone:"  
Label11="Mobile Phone:"  

Plik .txt można skompilować w pliku resources, wydając następujące polecenie:

PatientForm.txtresgen

Poniższy przykład wylicza zasoby w pliku PatientForm.resources i wyświetla nazwę i wartość każdego z nich.

using System;
using System.Collections;
using System.Resources;

public class Example
{
   public static void Main()
   {
      var rr = new ResourceReader("PatientForm.resources");
      IDictionaryEnumerator dict = rr.GetEnumerator();
      int ctr = 0;

      while (dict.MoveNext()) {
         ctr++;
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value);
      }

      rr.Close();
   }
}
// The example displays the following output:
//       01: Label3 = "Species:"
//       02: Label2 = "Pet Name:"
//       03: Label1 = "Patient Number:"
//       04: Label7 = "Owner:"
//       05: Label6 = "Age:"
//       06: Label5 = "Date of Birth:"
//       07: Label4 = "Breed:"
//       08: Label9 = "Home Phone:"
//       09: Label8 = "Address:"
//       10: Title = "Top Pet Animal Clinic"
//       11: Label10 = "Work Phone:"
//       12: Label11 = "Mobile Phone:"
Imports System.Collections
Imports System.Resources

Module Example
   Public Sub Main()
      Dim rr As New ResourceReader("PatientForm.resources")
      Dim dict As IDictionaryEnumerator = rr.GetEnumerator
      Dim ctr As Integer

      Do While dict.MoveNext()
         ctr += 1
         Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value)
      Loop
      
      rr.Close()
   End Sub
End Module
' The example displays the following output:
'       01: Label3 = "Species:"
'       02: Label2 = "Pet Name:"
'       03: Label1 = "Patient Number:"
'       04: Label7 = "Owner:"
'       05: Label6 = "Age:"
'       06: Label5 = "Date of Birth:"
'       07: Label4 = "Breed:"
'       08: Label9 = "Home Phone:"
'       09: Label8 = "Address:"
'       10: Title = "Top Pet Animal Clinic"
'       11: Label10 = "Work Phone:"
'       12: Label11 = "Mobile Phone:"

Uwagi

Zazwyczaj zasoby są wyliczane przez wywołanie GetEnumerator metody , a następnie wielokrotnie wywoływanie MoveNext metody dla zwracanego IDictionaryEnumerator obiektu do momentu zwrócenia falsemetody . Nazwa zasobu jest dostępna z IDictionaryEnumerator.Key właściwości; jej wartość z IDictionaryEnumerator.Value właściwości. W przykładzie pokazano, jak wyliczać zasoby w ten sposób.

Implementacja IDictionaryEnumerator.Value właściwości klasy ResourceReader może zgłaszać następujące wyjątki:

Wyjątek można obsłużyć przez wywołanie GetResourceData metody w celu pobrania informacji o typie danych i tablicy bajtów przypisanej do nazwanego zasobu. Aby uzyskać więcej informacji, zobacz sekcję "Pobieranie zasobów według nazwy za pomocą polecenia GetResourceData" w ResourceReader temacie klasy.

Ważne

Klasa ResourceReader zawiera dwie metody zwracające moduły wyliczające. Metoda GetEnumerator zwraca obiekt interfejsu i jest zalecaną IDictionaryEnumerator metodą wywoływania podczas wyliczania zasobów.

Dotyczy

Zobacz też