mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00] 1.0.5000.0 2.0.0.0 4.0.0.0 Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details. System.Object System.Resources.IResourceReader System.Runtime.InteropServices.ComVisible(true)

The class provides a standard implementation of the interface. A instance represents either a standalone .resources file or a .resources file that is embedded in an assembly. It is used to enumerate the resources in a .resources file and retrieve its name/value pairs. It differs from the class, which is used to retrieve specified named resources from a .resources file that is embedded in an assembly. The class is used to retrieve resources whose names are known in advance, whereas the class is useful for retrieving resources whose number or precise names are not known at compile time. For example, an application may use a resources file to store configuration information that is organized into sections and items in a section, where the number of sections or items in a section is not known in advance. Resources can then be named generically (such as Section1, Section1Item1, Section1Item2, and so on) and retrieved by using a object.

For more information about using the class, see the following sections:

Instantiating a ResourceReader object

Enumerating a ResourceReader object's resources

Retrieving resources by using IDictionaryEnumerator properties

Retrieving resources by name with GetResourceData

## Instantiating a ResourceReader Object

A .resources file is a binary file that has been compiled from either a text file or an XML .resx file by Resgen.exe (Resource File Generator). A object can represent either a standalone .resources file or a .resources file that has been embedded in an assembly.

To instantiate a object that reads from a standalone .resources file, use the class constructor with either an input stream or a string that contains the .resources file name. The following example illustrates both approaches. The first instantiates a object that represents a .resources file named Resources1.resources by using its file name. The second instantiates a object that represents a .resources file named Resources2.resources by using a stream created from the file.

code reference: System.Resources.ResourceReader.Class#2

To create a object that represents an embedded .resources file, instantiate an object from the assembly in which the .resources file is embedded. Its method returns a object that can be passed to the constructor. The following example instantiates a object that represents an embedded .resources file.

code reference: System.Resources.ResourceReader.Class#3

## Enumerating a ResourceReader Object's Resources

To enumerate the resources in a .resources file, you call the method, which returns an object. You call the IDictionaryEnumerator.MoveNext method to move from one resource to the next. The method returns false when all the resources in the .resources file have been enumerated.

Although the class implements the interface and the method, the method does not provide the implementation. Instead, the method returns an interface object that provides access to each resource's name/value pair.

You can retrieve the individual resources in the collection in two ways:

You can iterate each resource in the collection and use properties to retrieve the resource name and value. We recommend this technique when all the resources are of the same type, or you know the data type of each resource.

You can retrieve the name of each resource when you iterate the collection and call the method to retrieve the resource's data. We recommend this approach when you do not know the data type of each resource or if the previous approach throws exceptions.

## Retrieving Resources by Using IDictionaryEnumerator Properties

The first method of enumerating the resources in a .resources file involves directly retrieving each resource's name/value pair. After you call the IDictionaryEnumerator.MoveNext method to move to each resource in the collection, you can retrieve the resource name from the property and the resource data from the property.

The following example shows how to retrieve the name and value of each resource in a .resources file by using the and properties. To run the example, create the following text file named ApplicationResources.txt to define string resources.

`Title="Contact Information" Label1="First Name:" Label2="Middle Name:" Label3="Last Name:" Label4="SSN:" Label5="Street Address:" Label6="City:" Label7="State:" Label8="Zip Code:" Label9="Home Phone:" Label10="Business Phone:" Label11="Mobile Phone:" Label12="Other Phone:" Label13="Fax:" Label14="Email Address:" Label15="Alternate Email Address:"`

You can then convert the text resource file to a binary file named ApplicationResources.resources by using the following command:

resgen ApplicationResources.txt

The following example then uses the class to enumerate each resource in the standalone binary .resources file and to display its key name and corresponding value.

code reference: System.Resources.ResourceReader.Class#1

The attempt to retrieve resource data from the property can throw the following exceptions:

A if the data is not in the expected format.

A if the assembly that contains the type to which the data belongs cannot be found.

A if the type to which the data belongs cannot be cannot be found.

Typically, these exceptions are thrown if the .resources file has been modified manually, if the assembly in which a type is defined has either not been included with an application or has been inadvertently deleted, or if the assembly is an older version that predates a type. If one of these exceptions is thrown, you can retrieve resources by enumerating each resource and calling the method, as the following section shows. This approach provides you with some information about the data type that the property attempted to return.

## Retrieving Resources by Name with GetResourceData

The second approach to enumerating resources in a .resources file also involves navigating through the resources in the file by calling the IDictionaryEnumerator.MoveNext method. For each resource, you retrieve the resource's name from the property, which is then passed to the method to retrieve the resource's data. This is returned as a byte array in the argument.

This approach is more awkward than retrieving the resource name and value from the and properties, because it returns the actual bytes that form the resource value. However, if the attempt to retrieve the resource throws an exception, the method can help identify the source of the exception by supplying information about the resource's data type. For more information about the string that indicates the resource's data type, see .

The following example illustrates how to use this approach to retrieve resources and to handle any exceptions that are thrown. It programmatically creates a binary .resources file that contains four strings, one Boolean, one integer, one bitmap, and one custom DateTimeTZI object. To run the example, do the following:

Create an assembly named Library.dll that contains the DateTimeTZI structure. The following is the source code for the assembly.

code reference: System.Resources.ResourceReader.Class#4

Compile the source code in C# by using the following command:

`csc /t:library library.cs`

Or, you can compile it in Visual Basic by using the following command:

`vbc library.vb /t:library`

Compile and execute the following source code, which creates a .resources file named ContactResources.resources.

code reference: System.Resources.ResourceReader.Class#5

The source code file is named CreateResources.cs. You can compile it in C# by using the following command:

`csc CreateResources.cs /r:library.dll`

Or, you can compile it in Visual Basic by using the following command:

`vbc CreateResources.vb /r:library.dll`

Compile and run the following code to enumerate the resources in the ContactResources.resources file.

code reference: System.Resources.ResourceReader.Class#6

After modifying the source code (for example, by deliberately throwing a at the end of the try block) or renaming the Library.dll assembly so that it is unavailable at runtime, you can run the example to see how calls to enable you to retrieve or recreate some resource information.

Enumerates the resources in a binary resources (.resources) file by reading sequential resource name/value pairs.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The constructor instantiates a object that retrieves resources either from a standalone .resources file or from a .resources file that is embedded in an assembly. To read from a standalone .resources file, instantiate a object and pass it to the constructor. To read from an embedded .resources file, call the method with the case-sensitive name of the .resources file, and pass the returned object to the constructor.

  Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Untrusted Data Security Risks.

  Initializes a new instance of the class for the specified stream.

  The input stream for reading resources.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The constructor instantiates a object that retrieves resources from a standalone .resources file. To retrieve resources from an embedded .resources file, use the constructor.

  Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Untrusted Data Security Risks.

  Initializes a new instance of the class for the specified named resource file.

  The path and name of the resource file to read. is not case-sensitive.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  can be safely called multiple times.

  Releases all operating system resources associated with this object.

- Method
  4.0.0.0
  System.Void

  When you are finished using this instance of , call to release all resources used by this instance. You should eliminate further references to this instance so that the garbage collector can reclaim the memory of the instance instead of keeping it alive for finalization.

  calls the private Dispose(Boolean) method, which contains the code to release managed and unmanaged resources. For more information, see Implementing a Dispose Method.

  Releases all resources used by the current instance of the class.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Collections.IDictionaryEnumerator

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

  The implementation of the property by the class can throw the following exceptions:

  The assembly that contains the type to which the data belongs cannot be found.

  The data is not in the expected format.

  The type to which the data belongs cannot be found.

  You can handle the exception by calling the 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 class topic.

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

  Returns an enumerator for this object.

  An enumerator for this object.

- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` To be added. To be added. To be added. To be added. To be added.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Collections.IEnumerator

  is an explicit interface implementation. It can be used only when the instance is cast to an interface. The recommended approach to enumerating the resources in a .resources file is to call the method of the object returned by the method.

  Returns an enumerator for this object.

  An enumerator for this object.

- Method
  System.Void

  This member is an explicit interface member implementation. It can be used only when the instance is cast to an interface.

  Releases all resources used by the object.

  1.0.5000.0
  2.0.0.0