ResourceWriter::AddResource Method (String^, String^)

 

Adds a string resource to the list of resources to be written.

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

public:
virtual void AddResource(
	String^ name,
	String^ value
) sealed

Parameters

name
Type: System::String^

The name of the resource.

value
Type: System::String^

The value of the resource.

Exception Condition
ArgumentException

name (or a name that varies only by capitalization) has already been added to this ResourceWriter.

ArgumentNullException

The name parameter is null.

InvalidOperationException

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

The resource is not written until Generate is called.

You can retrieve the resources written by the AddResource(String^, String^) method by calling the ResourceManager::GetString method.

The following example uses the AddResource method to add string resources to a ResourceWriter object.

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" );

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

.NET Framework
Available since 1.1
Return to top
Show: