ResourceReader.GetEnumerator Method ()

 

Returns an enumerator for this ResourceReader object.

Namespace:   System.Resources
Assembly:  mscorlib (in mscorlib.dll)

Public Function GetEnumerator As IDictionaryEnumerator

Return Value

Type: System.Collections.IDictionaryEnumerator

An enumerator for this ResourceReader object.

Exception Condition
InvalidOperationException

The reader has been closed or disposed, and cannot be accessed.

Typically, you enumerate resources by calling the GetEnumerator method and then repeatedly calling the MoveNext method on the returned IDictionaryEnumerator object until the method returns false. The resource name is available from the IDictionaryEnumerator.Key property; its value from the IDictionaryEnumerator.Value property. The example illustrates how to enumerate resources in this way.

The implementation of the IDictionaryEnumerator.Value property by the ResourceReader class can throw the following exceptions:

You can handle the exception by calling the GetResourceData method to retrieve information about the data type and the byte array assigned to the named resource. For more information, see the "Retrieving Resources by Name with GetResourceData" section in the ResourceReader class topic.

System_CAPS_importantImportant

The ResourceReader class includes two methods that return enumerators. The GetEnumerator method returns an IDictionaryEnumerator interface object and is the recommended method to call when enumerating resources.

The example in this section uses the following .txt file named PatientForm.txt to define the resources used by an application.


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

You can compile the .txt file into a .resources file by issuing the following command:

resgen PatientForm.txt

The following example enumerates the resources in PatientForm.resources and displays the name and value of each.

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

.NET Framework
Available since 1.1
Return to top
Show: