System.Resources.ResourceReader Class

Assembly: Mscorlib.dll
Namespace: System.Resources
Summary
Enumerates .resources files and streams, reading sequential resource name and value pairs.
C# Syntax:
public sealed class ResourceReader : IResourceReader, IEnumerable, IDisposable
Remarks
The ResourceReader provides a default implementation of the IResourceReader interface.

You can use resource readers to read resource name and resource value pairs from .resources files. The resources can be enumerated by traversing the IDictionaryEnumerator returned by the ResourceReader.GetEnumerator method. The methods provided by the IDictionaryEnumerator are used to advance to the next resource and read the name and value of each resource in the .resources file.



Note IEnumerable.GetEnumerator returns an IEnumerator not IDictionaryEnumerator.
Example
The following code sample displays the content of "myResources.resources" files on the console:
using System;
using System.Resources;
using System.Collections;
 
public class ReadResources {

   public static void Main(string[] args) {

      // Opens a resource reader and gets an enumerator from it.
      IResourceReader reader = new ResourceReader("myResources.resources");
      IDictionaryEnumerator en = reader.GetEnumerator();
      
      // Goes through the enumerator, printing out the key and value pairs.
      while (en.MoveNext()) {
         Console.WriteLine();
         Console.WriteLine("Name: {0}", en.Key);
         Console.WriteLine("Value: {0}", en.Value);
      }
      reader.Close();
   }
}

    
See also:
System.Resources Namespace See also:
MSDN: designingglobalapplications | IResourceReader

System.Resources.ResourceReader Member List:

Public Constructors
ctor #1 Overloaded:
.ctor(Stream stream)

Initializes a new instance of the ResourceReader class for the specified stream.
ctor #2 Overloaded:
.ctor(string fileName)

Initializes a new instance of the ResourceReader class for the specified resource file.
Public Methods
Close Releases all operating system resources associated with this ResourceReader.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetEnumerator Returns an enumerator for this ResourceReader.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.
Explicit Interface Implementations 
IEnumerable.GetEnumerator Returns an enumerator for this ResourceReader.
IDisposable.Dispose Releases the resources used by the ResourceReader.

Hierarchy:


System.Resources.ResourceReader Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the ResourceReader class for the specified stream.
C# Syntax:
public ResourceReader(
   Stream stream
);
Parameters:

stream

The input stream for reading resources.

Exceptions
Exception Type Condition
ArgumentException The stream is not readable.
ArgumentNullException The stream parameter is null.
IOException An I/O error has occured while accessing stream.

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the ResourceReader class for the specified resource file.
C# Syntax:
public ResourceReader(
   string fileName
);
Parameters:

fileName

The path of the resource file to be read.

Exceptions
Exception Type Condition
ArgumentNullException The fileName parameter is null.
FileNotFoundException The file cannot be found.
IOException An I/O error has occured.

Return to top


Method: Close()
Summary
Releases all operating system resources associated with this ResourceReader.
C# Syntax:
public void Close();
Implements:
IResourceReader.Close
Remarks
ResourceReader.Close can be safely called multiple times.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~ResourceReader();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetEnumerator()
Summary
Returns an enumerator for this ResourceReader.
C# Syntax:
public IDictionaryEnumerator GetEnumerator();
Return Value:
An IDictionaryEnumerator for this ResourceReader.
Exceptions
Exception Type Condition
InvalidOperationException The reader has already been closed, and thus cannot be accessed.
Implements:
IResourceReader.GetEnumerator
See also:
IDictionary | IDictionaryEnumerator

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: IEnumerable.GetEnumerator()
Summary
Returns an enumerator for this ResourceReader.
C# Syntax:
IEnumerator IEnumerable.GetEnumerator();
Return Value:
An IEnumerator for this ResourceReader.
Exceptions
Exception Type Condition
InvalidOperationException The reader has already been closed, and thus cannot be accessed.
Implements:
IEnumerable.GetEnumerator
See also:
IDictionary | IDictionaryEnumerator

Return to top


Method: IDisposable.Dispose()
Summary
Releases the resources used by the ResourceReader.
C# Syntax:
void IDisposable.Dispose();
Implements:
IDisposable.Dispose
Remarks
Calling ResourceReader.Dispose allows the resources used by the ResourceReader to be reallocated for other purposes. For more information about ResourceReader.Dispose, see the conceptual topic at MSDN: cleaningupunmanagedresources.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.