This topic has not yet been rated - Rate this topic

ResourceWriter Class

Writes resources in the system-default format to an output file or an output stream. This class cannot be inherited.

System.Object
  System.Resources.ResourceWriter

Namespace:  System.Resources
Assembly:  mscorlib (in mscorlib.dll)
[ComVisibleAttribute(true)]
public sealed class ResourceWriter : IResourceWriter, 
	IDisposable

The ResourceWriter type exposes the following members.

  Name Description
Public method ResourceWriter(Stream) Initializes a new instance of the ResourceWriter class that writes the resources to the provided stream.
Public method ResourceWriter(String) Initializes a new instance of the ResourceWriter class that writes the resources to the specified file.
Top
  Name Description
Public property 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.
Top
  Name Description
Public method AddResource(String, Byte[]) Adds a named resource specified as a byte array to the list of resources to be written.
Public method AddResource(String, Stream) Adds a named resource specified as a stream to the list of resources to be written.
Public method AddResource(String, Object) Adds a named resource specified as an object to the list of resources to be written.
Public method AddResource(String, String) Adds a String resource to the list of resources to be written.
Public method 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.
Public method AddResourceData Adds a unit of data as a resource to the list of resources to be written.
Public method Close Saves the resources to the output stream and then closes it.
Public method Dispose Allows users to close the resource file or stream, explicitly releasing resources.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Generate Saves all resources to the output stream in the system default format.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top

ResourceWriter provides a default implementation of the IResourceWriter interface.

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.

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.

The following example writes several strings into the myResources.resources file.


using System;
using System.Resources;


public class WriteResources {
   public static void Main(string[] args) {

      // Creates a resource writer.
      IResourceWriter writer = new 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();
   }
}


.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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ