Export (0) Print
Expand All

ResourceManager.ResourceManager(String, Assembly) Constructor

Initializes a new instance of the ResourceManager class that looks up resources contained in files derived from the specified root name using the given Assembly.

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

public:
ResourceManager (
	String^ baseName, 
	Assembly^ assembly
)
public ResourceManager (
	String baseName, 
	Assembly assembly
)
public function ResourceManager (
	baseName : String, 
	assembly : Assembly
)
Not applicable.

Parameters

baseName

The root name of the resources. For example, the root name for the resource file named "MyResource.en-US.resources" is "MyResource".

assembly

The main Assembly for the resources.

Exception typeCondition

ArgumentNullException

The baseName or assembly parameter is a null reference (Nothing in Visual Basic).

The individual resource files should be contained in satellite assemblies with the invariant culture's.resources file contained in the main assembly. A satellite assembly is assumed to contain resources for a single culture specified in that assembly's manifest, and are loaded as necessary.

This constructor uses the system provided ResourceSet implementation. To use a custom resource file format, you should derive from the ResourceSet class, override GetDefaultReader and GetDefaultWriter, and pass that type to the constructor that takes a Type as the third parameter. Using a custom ResourceSet can be useful for controlling resource caching policy or supporting your own resource file format, but is generally not necessary.

The following code example defines a new instance of the ResourceManager class that looks for executing assemblies under the item's root name. The code then checks for the culture of the currently executing thread and displays a culture-appropriate welcome message.

using namespace System;
using namespace System::Globalization;
using namespace System::Threading;
using namespace System::Resources;
using namespace System::Reflection;
int main()
{
   
   // Create a resource manager to retrieve resources.
   ResourceManager^ rm = gcnew ResourceManager( "items",Assembly::GetExecutingAssembly() );
   
   // Get the culture of the currently executing thread.
   // The value of ci will determine the culture of
   // the resources that the resource manager retrieves.
   CultureInfo^ ci = Thread::CurrentThread->CurrentCulture;
   
   // Retrieve the value of the string resource named
   // S"welcome", localized for the culture specified by ci.
   String^ str = rm->GetString( "welcome", ci );
   Console::WriteLine( str );
}


import System.*;
import System.Globalization.*;
import System.Threading.*;
import System.Resources.*;
import System.Reflection.*;

class ResourcesExample
{

    public static void main(String[] args)
    {
        // Create a resource manager to retrieve resources.
        ResourceManager rm = new ResourceManager("items", 
            Assembly.GetExecutingAssembly());

        // Get the culture of the currently executing thread.
        // The value of ci will determine the culture of
        // the resources that the resource manager retrieves.
        CultureInfo ci = 
            System.Threading.Thread.get_CurrentThread().get_CurrentCulture();

        // Retrieve the value of the string resource named 
        // "welcome", localized for the culture specified by ci.
        String str = rm.GetString("welcome", ci);
        Console.WriteLine(str);
    } //main
} //ResourcesExample

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft