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

Moduł wyliczający dla tego ResourceReader obiektu.

Implementuje

Wyjątki

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

Przykłady

W przykładzie w tej sekcji użyto następującego pliku .txt o nazwie PatientForm.txt w 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ć do pliku resources, wydając następujące polecenie:

PatientForm.txtponownego generowania

Poniższy przykład wylicza zasoby w PatientForm.resources pliku 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

Zwykle wylicza się zasoby przez wywołanie GetEnumerator metody , a następnie wielokrotnie wywołuje MoveNext metodę dla zwróconego IDictionaryEnumerator obiektu, dopóki metoda nie zwróci falsemetody . Nazwa zasobu jest dostępna z IDictionaryEnumerator.Key właściwości ; jej wartość z IDictionaryEnumerator.Value właściwości . W tym przykładzie pokazano, jak wyliczać zasoby w ten sposób.

Implementacja IDictionaryEnumerator.Value właściwości przez klasę 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ą getResourceData" w temacie ResourceReader klasy.

Ważne

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

Dotyczy

Zobacz też