ResourceReader.GetEnumerator Metódus

Definíció

Egy enumerátort ad vissza ehhez az ResourceReader objektumhoz.

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

Válaszok

Az objektum enumerátora ResourceReader .

Megvalósítás

Kivételek

Az olvasót bezárták vagy eltávolították, és nem érhető el.

Példák

Az ebben a szakaszban szereplő példa a következő .txt nevű fájlt PatientForm.txt használja az alkalmazás által használt erőforrások meghatározásához.

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:"

A .txt fájlt .resources fájlba fordíthatja az alábbi parancs kiadásával:

resgen PatientForm.txt

Az alábbi példa felsorolja a benne lévő PatientForm.resources erőforrásokat, és megjeleníti az egyes erőforrások nevét és értékét.

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:"

Megjegyzések

Az erőforrásokat általában a metódus meghívásával GetEnumerator , majd a MoveNext metódus ismételt meghívásával számba kell adnia a visszaadott IDictionaryEnumerator objektumon, amíg a metódus vissza nem tér false. Az erőforrás neve elérhető a IDictionaryEnumerator.Key tulajdonságból, értéke pedig a IDictionaryEnumerator.Value tulajdonságból. A példa bemutatja, hogyan lehet ilyen módon számba adni az erőforrásokat.

A tulajdonság osztály általi ResourceReader megvalósítása IDictionaryEnumerator.Value a következő kivételeket okozhatja:

A kivételt úgy kezelheti, hogy meghívja a metódust az GetResourceData adattípusra és a névvel ellátott erőforráshoz rendelt bájttömbre vonatkozó információk lekéréséhez. További információ: "Erőforrások lekérése név szerint a GetResourceData használatával" című szakasz az ResourceReader osztály témakörében.

Important

Az ResourceReader osztály két metódust tartalmaz, amelyek enumerátorokat adnak vissza. A GetEnumerator metódus egy IDictionaryEnumerator interfészobjektumot ad vissza, és az erőforrások számbavételekor ajánlott meghívni.

A következőre érvényes:

Lásd még