ResourceWriter::Generate Method ()

 

Saves all resources to the output stream in the system default format.

Namespace:   System.Resources
Assembly:  mscorlib (in mscorlib.dll)

public:
virtual void Generate() sealed

Exception Condition
IOException

An I/O error occurred.

SerializationException

An error occurred during serialization of the object.

InvalidOperationException

This ResourceWriter has been closed and its hash table is unavailable.

The Generate method is called implicitly by the Close method if it is not called by your application code.

Generate can only be called once, after all calls to AddResource and AddResourceData have been made. If an exception occurs while writing the resources, the output stream will be closed to prevent writing invalid information.

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 Close after calling Generate, or simply call Close.

The following code example uses the Generate method to write all resource objects in a ResourceWriter class to the output stream

using namespace System;
using namespace System::Resources;
using namespace System::IO;
int main()
{

   // Create a file stream to encapsulate items.resources.
   FileStream^ fs = gcnew FileStream( "items.resources",FileMode::OpenOrCreate,FileAccess::Write );

   // Open a resource writer to write from the stream.
   IResourceWriter^ writer = gcnew 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" );

   // Generate the resources, and close the writer.
   writer->Generate();
   writer->Close();
}

.NET Framework
Available since 1.1
Return to top
Show: