ResourceManager Constructor (Type)
Initializes a new instance of the ResourceManager class that looks up resources in satellite assemblies based on information from the specified type object.
Assembly: mscorlib (in mscorlib.dll)
In desktop apps, the resource manager uses the resourceSource parameter to load a particular resource file as follows:
If the NeutralResourcesLanguageAttribute attribute is not used to indicate that the resources of the default culture reside in a satellite assembly, the resource manager assumes that the resource file for the default culture is found in the same assembly as the type specified by the resourceSource parameter.
The resource manager assumes that the default resource file has the same base name as the type specified by the resourceSource parameter.
The resource manager uses the default ResourceSet class to manipulate the resource file.
For example, given a type named MyCompany.MyProduct.MyType, the resource manager looks for a .resources file named MyCompany.MyProduct.MyType.resources in the assembly that defines MyType.
In Visual Studio, the Resource Designer automatically generates code that defines an internal (in C#) or Friend (in Visual Basic) class whose name is the same as the base name of the .resources file for the default culture. This makes it possible to instantiate a ResourceManager object and couple it with a particular set of resources by getting a type object whose name corresponds to the name of the resource, because as long as the class is visible to the compiler, the resources must be as well. For example, if a .resources file is named Resource1, the following statement instantiates a ResourceManager object to manage the .resources file named Resource1:
If you're not using Visual Studio, you can create a class with no members whose namespace and name are the same as that of the default .resources file. The example provides an illustration.
Windows Store Apps
Although the ResourceManager class is supported in Windows Store apps, we do not recommend its use. Use this class only when you develop Portable Class Library projects that can be used with Windows Store apps. To retrieve resources from Windows Store apps, use the Windows.ApplicationModel.Resources.ResourceLoader class instead.
In Windows Store apps, ResourceManager uses the resourceSource parameter to infer the assembly, base name, and the namespace where the resource items can be located within the app's package resource index (PRI) file. For example, given a type named MyCompany.MyProduct.MyType that is defined in MyAssembly, the resource manager looks for a resource set identifier named MyAssembly and looks for a scope MyCompany.MyProduct.MyType within that resource set. The resource manager searches for resource items under the default context (current culture, current high contrast setting, and so on) within this scope.
The following example uses the constructor to instantiate a ResourceManager object. It consists of resources compiled from .txt files for the English (en), French (France) (fr-FR), and Russian (Russia) (ru-RU) cultures. The example changes the current culture and current UI culture to English (United States), French (France), Russian (Russia), and Swedish (Sweden). It then calls the GetString(String) method to retrieve the localized string, which displays a greeting that depends on the time of day.
The example requires three text-based resource files, as listed in the following table. Each file includes string resources named Morning, Afternoon, and Evening.
You can use the following batch file to compile the Visual Basic example and create an executable named Greet.exe. To compile with C#, change the compiler name from vbc to csc and the file extension from .vb to .cs.
resgen GreetingResources.txt vbc Greet.vb /resource: GreetingResources.resources md fr-FR resgen GreetingResources.fr-FR.txt al /out:fr-FR\Greet.resources.dll /culture:fr-FR /embed: GreetingResources.fr-FR.resources md ru-RU resgen GreetingResources.ru-RU.txt al /out:ru-RU\Greet.resources.dll /culture:ru-RU /embed: GreetingResources.ru-RU.resources
Here's the source code for the example (ShowDate.vb for the Visual Basic version or ShowDate.cs for the C# version of the code).
In addition to defining an app class named Example, the source code defines an internal class whose name, GreetingResources, is the same as the base name of the resource files. This makes it possible to successfully instantiate a ResourceManager object by calling the constructor.
Notice that the output displays the appropriate localized string except when the current UI culture is Swedish (Sweden), in which case it uses English language resources. Because Swedish language resources are unavailable, the app uses the resources of the default culture, as defined by the NeutralResourcesLanguageAttribute attribute, instead.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8