ResXResourceReader Class

Enumerates XML resource (.resx) files and streams, and reads the sequential resource name and value pairs.

System.Object
  System.Resources.ResXResourceReader

Namespace:  System.Resources
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
public class ResXResourceReader : IResourceReader, 
	IEnumerable, IDisposable

The ResXResourceReader type exposes the following members.

  NameDescription
Public methodResXResourceReader(Stream)Initializes a new instance of the ResXResourceReader class for the specified stream.
Public methodResXResourceReader(String)Initializes a new instance of the ResXResourceReader class for the specified resource file.
Public methodResXResourceReader(TextReader)Initializes a new instance of the ResXResourceReader class for the specified TextReader.
Public methodResXResourceReader(Stream, ITypeResolutionService)Initializes a new instance of the ResXResourceReader class using an input stream and a type resolution service.
Public methodResXResourceReader(Stream, AssemblyName[])Initializes a new instance of the ResXResourceReader class using a stream and an array of assembly names.
Public methodResXResourceReader(String, ITypeResolutionService)Initializes a new instance of the ResXResourceReader class using a file name and a type resolution service.
Public methodResXResourceReader(String, AssemblyName[])Initializes a new instance of the ResXResourceReader class using an XML resource file name and an array of assembly names.
Public methodResXResourceReader(TextReader, ITypeResolutionService)Initializes a new instance of the ResXResourceReader class using a text stream reader and a type resolution service.
Public methodResXResourceReader(TextReader, AssemblyName[])Initializes a new instance of the ResXResourceReader class using a TextReader object and an array of assembly names.
Top

  NameDescription
Public propertyBasePathGets or sets the base path for the relative file path specified in a ResXFileRef object.
Public propertyUseResXDataNodesGets or sets a value indicating whether ResXDataNode objects are returned when reading the current XML resource file or stream.
Top

  NameDescription
Public methodCloseReleases all resources used by the ResXResourceReader.
Protected methodDisposeReleases the unmanaged resources used by the ResXResourceReader and optionally releases the managed resources.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeThis member overrides the Finalize method. (Overrides Object.Finalize().)
Public methodStatic memberFromFileContents(String)Creates a new ResXResourceReader object and initializes it to read a string whose contents are in the form of an XML resource file.
Public methodStatic memberFromFileContents(String, ITypeResolutionService)Infrastructure. Creates a new ResXResourceReader object and initializes it to read a string whose contents are in the form of an XML resource file, and to use an ITypeResolutionService object to resolve type names specified in a resource.
Public methodStatic memberFromFileContents(String, AssemblyName[])Infrastructure. Creates a new ResXResourceReader object and initializes it to read a string whose contents are in the form of an XML resource file, and to use an array of AssemblyName objects to resolve type names specified in a resource.
Public methodGetEnumeratorReturns an enumerator for the current ResXResourceReader object.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetMetadataEnumeratorProvides a dictionary enumerator that can retrieve the design-time properties from the current XML resource file or stream.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<TResult>Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDisposable.DisposeInfrastructure. Releases the unmanaged resources used by the ResXResourceReader and optionally releases the managed resources. For a description of this member, see IDisposable.Dispose.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorInfrastructure. Returns an enumerator for the current ResXResourceReader object. For a description of this member, see IEnumerable.GetEnumerator.
Top

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.

NoteNote

This class contains a link demand and an inheritance demand at the class level that applies to all members. A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see Link Demands and Inheritance Demands.

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.


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");

      // 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();
   }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft