This topic contains the following sections.
The Resources Layer
The Resources Layer contains all localizable text for the application complete with a corresponding set of properties and methods for accessing each piece of text.
Text is resourced in the usual manner, using the Resource Editor from within Visual Studio. Or if you prefer, the .resx files which are simply Xml files, can be editted directly. In either case, Visual Studio automatically generates C# code that defines a strongly-typed resource class, complete with readonly properties corresponding to each entry in the .resx file.
The tool that auto-generates the C# code, ResXFileCodeGenerator, is native to Visual Studio. Unfortunately, VS2005 defines the classes with private accessors which means that there is no way to access the resources from outside the assembly. This is why we introduced a 3rd party tool which extends ResXFileCodeGenerator called ResXFileCodeGeneratorEx.
ResXFileCodeGeneratorEx allows the classes to be public -- meaning we can access the resources from any assembly that references Phoenix.Resources.dll. Below are two properties generated by the custom tool.
/// <summary> /// Looks up a localized string similar to 'Save'. /// </summary> public static string Common_Save { get { return ResourceManager.GetString("Common_Save", _resourceCulture); } } /// <summary> /// Looks up a localized string similar to 'Save and Close'. /// </summary> public static string Common_SaveAndClose { get { return ResourceManager.GetString("Common_SaveAndClose", _resourceCulture); } }
The ResXFileCodeGeneratorEx also scans the resource text for string.Format() style parameters. If any are present, it generates a method that accepts a parameter for each one found in the text. The resource text, and the parameter list can then be formatted into a string by calling string.Format(). As an example, suppose a resource key called ClickCount has the resource text of You clicked the button {0} times. ResXFileCodeGeneratorEx will generate the following method:
/// <summary> /// Formats a localized string similar to 'You clicked the button {0} times'. /// </summary> /// <param name="arg0">An object (0) to format.</param> /// <returns>A copy of format string in which the format items have been replaced by the String equivalent of the corresponding instances of Object in arguments.</returns> public static string ClickCountFormat(object arg0) { return string.Format(_resourceCulture, ClickCount, arg0); }
This useful feature makes accessing resource text much more robust, since the developer knows at design time what parameters are present in the resource text.
mybutton.Text = Resources.MyResource.ClickCountFormat(42);| Since the methods in this assembly are auto-generated by Visual Studio from the .resx files, this assembly has not been documented in the Phoenix Class Reference section. |
Assembly
Phoenix.Resources.dll
Satellite assemblies for each culture can be found in a subdirectory representing the culture. For example, the assembly with French text is found in
fr/Phoenix.Resources.resources.dll
and the Spanish text is in
es/Phoenix.Resources.resources.dll
Using the Resources
Resource text is accessed as you would normally expect, and is available in code-behind pages as well as class library projects (once a reference to Phoenix.Resources.dll is made). The ResourceManager class within each Resource class is responsible for retrieving the resource based on the UI culture of the current thread.
// Set the message to a string similar to 'Thanks for voting!'
lblVoteMessage.Text = Resources.Labels.Poll_ThanksForVoting;In an aspx page or ascx control, resource text can be accessed and sent directly to the response stream using the = character.
<h4> <%= Resources.Labels.Poll_Results %> </h4>
You can also use the ASP.NET explicit syntax which is used when you need to send the resource text to a property on another server control. The $ character is used in this case.
<asp:HyperLink ID="hlDownload" runat="server" Text="<%$ Resources:Labels, Common_Download %>" />
|
Normally, the ASP.NET page parser looks for resources in the App_GlobalResources folder. Since we have moved the resources to a seperate class library, the previous two examples will not work if the customized Expression Builder (Phoenix.HttpHandlers..::.MyExpressionBuilder) has not been configured in the web.config (it is configured by default). The code below shows how the expressionBuilders element is used to designate the class that will handle page Resource parsing. <expressionBuilders> <remove expressionPrefix="Resources" /> <add expressionPrefix="Resources" type="Phoenix.HttpHandlers.MyExpressionBuilder, Phoenix.UI" /> </expressionBuilders> |
Resource Classes
The Phoenix.Resources project currently has several .resx files. The resulting classes that are created by Visual Studio are shown below. All classes belong to the Resources namespace.

| Resource Class Name | Description |
|---|---|
| Controls | Contains words and phrases that are meant to be presented to the user as data within a control. |
| Errors | Error messages and other descriptive text that appears as the result of an error or some other condition. |
| Hints | Contains inline help text and other message that appear directly in the body text of the page. |
| Labels | Contains words and phrases that are meant to be rendered as labels in button text, hyperlinks and other controls. |
| Menus | The text that describes the modules is grouped in the Menus resource. There is a unified naming convention used in this resource file. The name of the module is the same as the resource key. A brief description of the module is found in a key formed by concatenating "desc" with the module name. |
| Metadata | The text that describes the metadata fields is grouped in the Metadata resource. |
| PageTitles | Titles of pages. |
| Tooltips | Contains phrases that provide additional guidance and are rendered as tooltips that appear when the user's mouse hovers over an item. |
