ResourceWriter Class
Updated: May 2012
Writes resources in the system-default format to an output file or an output stream. This class cannot be inherited.
Assembly: mscorlib (in mscorlib.dll)
The ResourceWriter type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ResourceWriter(Stream) | Initializes a new instance of the ResourceWriter class that writes the resources to the provided stream. |
![]() | ResourceWriter(String) | Initializes a new instance of the ResourceWriter class that writes the resources to the specified file. |
| Name | Description | |
|---|---|---|
![]() | TypeNameConverter | Gets or sets a delegate that enables resource assemblies to be written that target versions of the .NET Framework prior to the .NET Framework version 4 by using qualified assembly names. |
| Name | Description | |
|---|---|---|
![]() | AddResource(String, array<Byte>) | Adds a named resource specified as a byte array to the list of resources to be written. |
![]() | AddResource(String, Stream) | Adds a named resource specified as a stream to the list of resources to be written. |
![]() | AddResource(String, Object) | Adds a named resource specified as an object to the list of resources to be written. |
![]() | AddResource(String, String) | Adds a string resource to the list of resources to be written. |
![]() | AddResource(String, Stream, Boolean) | Adds a named resource specified as a stream to the list of resources to be written, and specifies whether the stream should be closed after the Generate method is called. |
![]() | AddResourceData | Adds a unit of data as a resource to the list of resources to be written. |
![]() | Close | Saves the resources to the output stream and then closes it. |
![]() | Dispose | Allows users to close the resource file or stream, explicitly releasing resources. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | Generate | Saves all resources to the output stream in the system default format. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
ResourceWriter provides a default implementation of the IResourceWriter interface. It enables you to programmatically create a binary resource (.resources) file.
Resources are specified as name and value pairs using the AddResource method. Resource names are case-sensitive when used for lookups, but to more easily support authoring tools and help eliminate bugs, ResourceWriter will not allow a .resources file to have names that vary only by case. The ResourceWriter class enables you to create string, object, and binary resources. Binary resources can be written to the resource file as a byte array or a stream.
To create a resources file, create a ResourceWriter with a unique file name, call AddResource at least once, call Generate to write the resources file to disk, and then call Close to close the file. Calling Close will implicitly call Generate if you do not explicitly call Generate.
The resources will not necessarily be written in the same order they were added.
To retrieve resources from a binary .resources file created by the ResourceWriter class, you can use the ResourceManager class, which lets you retrieve named resources, or the ResourceReader class, which lets you enumerate all the resources in the file.
The following example writes several strings into the myResources.resources file.
using namespace System; using namespace System::Resources; int main() { // Creates a resource writer. IResourceWriter^ writer = gcnew ResourceWriter( "myResources.resources" ); // Adds resources to the resource writer. writer->AddResource( "String 1", "First String" ); writer->AddResource( "String 2", "Second String" ); writer->AddResource( "String 3", "Third String" ); // Writes the resources to the file or stream, and closes it. writer->Close(); }
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.
