ResourceReader.GetEnumerator メソッド

定義

この ResourceReader オブジェクトの列挙子を返します。

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

戻り値

この ResourceReader オブジェクトの列挙子。

実装

例外

リーダーが閉じられているか、破棄されているため、アクセスできません。

このセクションの例では、 という名前 PatientForm.txt の次の.txt ファイルを使用して、アプリケーションで使用されるリソースを定義します。

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

次のコマンドを発行して、.txt ファイルを .resources ファイルにコンパイルできます。

resgen PatientForm.txt

次の例では、 内 PatientForm.resources のリソースを列挙し、それぞれの名前と値を表示します。

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

注釈

通常、リソースを列挙するには、 メソッドをGetEnumerator呼び出し、 メソッドが を返すまで、返されるIDictionaryEnumeratorオブジェクトの メソッドを繰り返し呼び出MoveNextfalseします。 リソース名は、 プロパティから IDictionaryEnumerator.Key 使用できます。その値は プロパティから取得されます IDictionaryEnumerator.Value 。 この例では、この方法でリソースを列挙する方法を示します。

クラスによる プロパティの IDictionaryEnumerator.Value 実装では、 ResourceReader 次の例外をスローできます。

例外を処理するには、 メソッドを GetResourceData 呼び出して、名前付きリソースに割り当てられたデータ型とバイト配列に関する情報を取得します。 詳細については、クラス トピックの「GetResourceData を使用した名前によるリソースの取得」セクションを ResourceReader 参照してください。

重要

クラスには ResourceReader 、列挙子を返す 2 つのメソッドが含まれています。 メソッドは GetEnumerator インターフェイス オブジェクトを IDictionaryEnumerator 返します。これは、リソースを列挙するときに呼び出すために推奨されるメソッドです。

適用対象

こちらもご覧ください