ResXResourceReader Class

 

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

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

System::Object
  System.Resources::ResXResourceReader

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

NameDescription
System_CAPS_pubmethodResXResourceReader(Stream^)

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

System_CAPS_pubmethodResXResourceReader(Stream^, array<AssemblyName^>^)

Initializes a new instance of the ResXResourceReader class using a stream and an array of assembly names.

System_CAPS_pubmethodResXResourceReader(Stream^, ITypeResolutionService^)

Initializes a new instance of the ResXResourceReader class using an input stream and a type resolution service.

System_CAPS_pubmethodResXResourceReader(String^)

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

System_CAPS_pubmethodResXResourceReader(String^, array<AssemblyName^>^)

Initializes a new instance of the ResXResourceReader class using an XML resource file name and an array of assembly names.

System_CAPS_pubmethodResXResourceReader(String^, ITypeResolutionService^)

Initializes a new instance of the ResXResourceReader class using a file name and a type resolution service.

System_CAPS_pubmethodResXResourceReader(TextReader^)

Initializes a new instance of the ResXResourceReader class for the specified TextReader.

System_CAPS_pubmethodResXResourceReader(TextReader^, array<AssemblyName^>^)

Initializes a new instance of the ResXResourceReader class using a TextReader object and an array of assembly names.

System_CAPS_pubmethodResXResourceReader(TextReader^, ITypeResolutionService^)

Initializes a new instance of the ResXResourceReader class using a text stream reader and a type resolution service.

NameDescription
System_CAPS_pubpropertyBasePath

Gets or sets the base path for the relative file path specified in a ResXFileRef object.

System_CAPS_pubpropertyUseResXDataNodes

Gets or sets a value that indicates whether ResXDataNode objects are returned when reading the current XML resource file or stream.

NameDescription
System_CAPS_pubmethodClose()

Releases all resources used by the ResXResourceReader.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the ResXResourceReader and optionally releases the managed resources.

System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

This member overrides the Finalize method. (Overrides Object::Finalize().)

System_CAPS_pubmethodSystem_CAPS_staticFromFileContents(String^)

Creates a new ResXResourceReader object and initializes it to read a string whose contents are in the form of an XML resource file.

System_CAPS_pubmethodSystem_CAPS_staticFromFileContents(String^, array<AssemblyName^>^)

This API supports the product infrastructure and is not intended to be used directly from your code. 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.

System_CAPS_pubmethodSystem_CAPS_staticFromFileContents(String^, ITypeResolutionService^)

This API supports the product infrastructure and is not intended to be used directly from your code. 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.

System_CAPS_pubmethodGetEnumerator()

Returns an enumerator for the current ResXResourceReader object.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetMetadataEnumerator()

Provides a dictionary enumerator that can retrieve the design-time properties from the current XML resource file or stream.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable::GetEnumerator()

This API supports the product infrastructure and is not intended to be used directly from your code. Returns an enumerator for the current ResXResourceReader object. For a description of this member, see the IEnumerable::GetEnumerator method.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDisposable::Dispose()

This API supports the product infrastructure and is not intended to be used directly from your code. Releases the unmanaged resources used by the ResXResourceReader and optionally releases the managed resources. For a description of this member, see the IDisposable::Dispose method.

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

The ResXResourceReader class 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 the ResourceReader class.

You use the ResXResourceReader class to enumerate resources in .resx files by traversing the dictionary enumerator (IDictionaryEnumerator) that is returned by the GetEnumerator method. You call the methods provided by IDictionaryEnumerator to advance to the next resource and to read the name and value of each resource in the .resx file.

System_CAPS_noteNote

The ResXResourceReader class provides two enumerators. The ResXResourceReader::GetEnumerator method returns an IDictionaryEnumerator object; we recommend that you use this method to enumerate resources. The ResXResourceReader::IEnumerable::GetEnumerator method is an explicit interface implementation that returns an IEnumerator object; we do not recommend its use.

The following example uses the GetEnumerator method to obtain an IDictionaryEnumerator object that is used to enumerate the resources in a .resx file. The example includes a CreateResourceFile routine that creates the necessary resource file.

No code example is currently available or this language may not be supported.

If the UseResXDataNodes property is true, the value of the IDictionaryEnumerator::Value property is a ResXDataNode object rather than the resource value. This makes a resource item's comment available from the ResXDataNode::Comment property. The following example sets the UseResXDataNodes property to true and enumerates the resources in a .resx file,

No code example is currently available or this language may not be supported.

If UseResXDataNodes is true, the ResXDataNode items in the enumeration can be either:

  • Named resources along with their data. In this case, the ResXDataNode::FileRef property is null.

  • Named resources along with the name of the file that contains the resource data. In this case, the ResXDataNode::FileRef property returns a ResXFileRef object that provides information about the resource, including its filename. If relative file names are used, you should always set the BasePath property to provide a reference point for the relative file path.

If you want to retrieve named resources from a .resx file rather than enumerating its resources, you can instantiate a ResXResourceSet object and call its GetString and GetObject methods.

System_CAPS_noteNote

The ResXResourceReader class contains a link demand and an inheritance demand at the class level that applies to all members. A SecurityException exception is thrown when either the immediate caller or the derived class does not have full-trust permission.

The following example demonstrates how to use a ResXResourceReader to iterate through the resources in a .resx file. First, the ResXResourceReaderrsxr 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.windows.forms.dll>
#using <System.dll>

using namespace System;
using namespace System::Resources;
using namespace System::Collections;
void main()
{

   // Create a ResXResourceReader for the file items.resx.
   ResXResourceReader^ rsxr = gcnew ResXResourceReader( "items.resx" );


   // Iterate through the resources and display the contents to the console.
   IEnumerator^ myEnum = rsxr->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DictionaryEntry^ d = safe_cast<DictionaryEntry^>(myEnum->Current);
      Console::WriteLine( "{0}:\t {1}", d->Key, d->Value );
   }


   //Close the reader.
   rsxr->Close();
}

SecurityAction::LinkDemand

for full trust for the immediate caller. This member cannot be used by partially trusted code.

SecurityAction::InheritanceDemand

for full trust for inheritors. This class cannot be inherited by partially trusted code.

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: