public sealed class ResourceWriter : IResourceWriter, IDisposable
|
Resources are specified as name and value pairs using the ResourceWriter.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 ResourceWriter.AddResource at least once, call ResourceWriter.Generate to write the resources file to disk, and then call ResourceWriter.Close to close the file. Calling ResourceWriter.Close will implicitly ResourceWriter.Generate the file if required.
The resources will not necessarily be written in the same order they were added.
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(); } }
ctor #1 | Overloaded:.ctor(Stream stream) Initializes a new instance of the ResourceWriter class that writes the resources to the provided stream. |
ctor #2 | Overloaded:.ctor(string fileName) Initializes a new instance of the ResourceWriter class that writes the resources to the specified file. |
AddResource | Overloaded:AddResource(string name, byte[] value) Adds a named resource specified as a byte array to the list of resources to be written. |
AddResource | Overloaded:AddResource(string name, object value) Adds a named resource specified as an object to the list of resources to be written. |
AddResource | Overloaded:AddResource(string name, string value) Adds a String 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 (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
Generate | Saves all resources to the output stream in the system default format. |
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. |
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. |
Hierarchy:
public ResourceWriter( |
stream
Exception Type | Condition |
---|---|
ArgumentException | The stream parameter is not writable. |
ArgumentNullException | The stream parameter is null. |
public ResourceWriter( |
fileName
Exception Type | Condition |
---|---|
ArgumentNullException | The fileName parameter is null. |
name
value
Exception Type | Condition |
---|---|
ArgumentException | name (or a name that varies only by capitalization) has already been added to this ResourceWriter. |
ArgumentNullException | The name or value parameter is null. |
InvalidOperationException | This ResourceWriter has been closed and its Hashtable is unavailable. |
name
value
Exception Type | Condition |
---|---|
ArgumentException | name (or a name that varies only by capitalization) has already been added to this ResourceWriter. |
ArgumentNullException | The name or value parameter is null. |
InvalidOperationException | This ResourceWriter has been closed and its Hashtable is unavailable. |
name
value
Exception Type | Condition |
---|---|
ArgumentException | name (or a name that varies only by capitalization) has already been added to this ResourceWriter. |
ArgumentNullException | The name or value parameter is null. |
InvalidOperationException | This ResourceWriter has been closed and its Hashtable is unavailable. |
public void Close(); |
Exception Type | Condition |
---|---|
IOException | An I/O error has occurred. |
SerializationException | An error has occurred during serialization of the object. |
public void Dispose(); |
Exception Type | Condition |
---|---|
IOException | An I/O error has occurred. |
SerializationException | An error has occurred during serialization of the object. |
~ResourceWriter(); |
public void Generate(); |
Exception Type | Condition |
---|---|
IOException | An I/O error occurred. |
SerializationException | An error occurred during serialization of the object. |
InvalidOperationException | This ResourceWriter has been closed and its Hashtable is unavailable. |
ResourceWriter.Generate does not close the output stream in normal cases. Unless you are combining extra data with your .resources file or need access to the stream afterwards, you should call ResourceWriter.Close after calling ResourceWriter.Generate, or simply call ResourceWriter.Close.
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |