ResourceWriter Constructors

Definition

Initializes a new instance of the ResourceWriter class.

Overloads

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.

ResourceWriter(Stream)

Source:
ResourceWriter.cs
Source:
ResourceWriter.cs
Source:
ResourceWriter.cs

Initializes a new instance of the ResourceWriter class that writes the resources to the provided stream.

public ResourceWriter (System.IO.Stream stream);

Parameters

stream
Stream

The output stream.

Exceptions

The stream parameter is not writable.

The stream parameter is null.

Examples

The following code example defines a new instance of the ResourceWriter class that writes to a specified stream. The code adds resources to the writer and writes the resources to the stream.

using System;
using System.Resources;
using System.IO;

public class WriteResources 
{
    public static void Main(string[] args) 
    {  
        // Create a file stream to encapsulate items.resources.
        FileStream fs = new FileStream("items.resources", 
        FileMode.OpenOrCreate,FileAccess.Write);

        // Open a resource writer to write from the stream.
        IResourceWriter writer = new ResourceWriter(fs);
    
        // Add resources to the resource writer.
        writer.AddResource("String 1", "First String");
        writer.AddResource("String 2", "Second String");
        writer.AddResource("String 3", "Third String");

        // Write the resources to the stream, and close it.
        writer.Close();
    }
}

See also

Applies to

.NET 9 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ResourceWriter(String)

Source:
ResourceWriter.cs
Source:
ResourceWriter.cs
Source:
ResourceWriter.cs

Initializes a new instance of the ResourceWriter class that writes the resources to the specified file.

public ResourceWriter (string fileName);

Parameters

fileName
String

The output file name.

Exceptions

The fileName parameter is null.

Examples

The following code example defines a new instance of the ResourceWriter class that will write to a specified file. The code adds resources to the writer and writes the resources to the 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();
   }
}

See also

Applies to

.NET 9 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1