ResXResourceReader Class
Enumerates XML resource (.resx) files and streams, and reads the sequential resource name and value pairs.
For a list of all members of this type, see ResXResourceReader Members.
System.Object
System.Resources.ResXResourceReader
[Visual Basic] Public Class ResXResourceReader Implements IResourceReader, IEnumerable, IDisposable [C#] public class ResXResourceReader : IResourceReader, IEnumerable, IDisposable [C++] public __gc class ResXResourceReader : public IResourceReader, IEnumerable, IDisposable [JScript] public class ResXResourceReader implements IResourceReader, IEnumerable, IDisposable
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
The ResXResourceReader provides a default implementation of the IResourceReader interface that reads resource information in an XML format. To read resource information from a binary resource format, use ResourceReader.
You can use resource readers to read resource name and value pairs from .resx files. The resources can be enumerated by traversing the IDictionaryEnumerator returned by the GetEnumerator method. You can use the methods provided by the IDictionaryEnumerator to advance to the next resource and read the name and value of each resource in the .resx file.
For more information on the format of a .resx file, see Resources in .Resx File Format.
Note IEnumerable.GetEnumerator returns an IEnumerator not IDictionaryEnumerator.
Example
[Visual Basic, C#, C++] The following example demonstrates how to use a ResXResourceReader to iterate through the resources in a .resx file. First, the ResXResourceReader rsxr is created for the file items.resx. Next, the GetEnumerator method is used to create an IDictionaryEnumerator to iterate through the resources and display the contents to the console.
[Visual Basic] Imports System Imports System.Resources Imports System.Collections Imports Microsoft.VisualBasic Class ReadResXResources Public Shared Sub Main() ' Create a ResXResourceReader for the file items.resx. Dim rsxr As ResXResourceReader rsxr = New ResXResourceReader("items.resx") ' Create an IDictionaryEnumerator to iterate through the resources. Dim id As IDictionaryEnumerator = rsxr.GetEnumerator() ' Iterate through the resources and display the contents to the console. Dim d As DictionaryEntry For Each d In rsxr Console.WriteLine(d.Key.ToString() + ":" + ControlChars.Tab + d.Value.ToString()) Next d 'Close the reader. rsxr.Close() End Sub End Class [C#] using System; using System.Resources; using System.Collections; class ReadResXResources { public static void Main() { // Create a ResXResourceReader for the file items.resx. ResXResourceReader rsxr = new ResXResourceReader("items.resx"); // Create an IDictionaryEnumerator to iterate through the resources. IDictionaryEnumerator id = rsxr.GetEnumerator(); // Iterate through the resources and display the contents to the console. foreach (DictionaryEntry d in rsxr) { Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString()); } //Close the reader. rsxr.Close(); } } [C++] #using <mscorlib.dll> #using <system.windows.forms.dll> using namespace System; using namespace System::Resources; using namespace System::Collections; void main() { // Create a ResXResourceReader for the file items.resx. ResXResourceReader* rsxr = new ResXResourceReader(S"items.resx"); // Create an IDictionaryEnumerator* to iterate through the resources. IDictionaryEnumerator* id = rsxr->GetEnumerator(); // Iterate through the resources and display the contents to the console. IEnumerator* myEnum = rsxr->GetEnumerator(); while (myEnum->MoveNext()) { DictionaryEntry* d = __try_cast<DictionaryEntry*>(myEnum->Current); Console::WriteLine(S"{0}:\t {1}", d->Key, d->Value); } //Close the reader. rsxr->Close(); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Resources
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
See Also
ResXResourceReader Members | System.Resources Namespace | Resources in .Resx File Format