Strongly-typed Resource Classes

Release 1.0 - ...

Visual Studio 2005 can automatically generate a strongly-typed resource class for a resource file, using a code generator tool called ResXFileCodeGenerator. The tool generates a strongly-typed static property get function for each available resource, using the resource identifier as the property name. Client code can now retrieve resources by calling the static property getters, resulting in a more concise syntax with the added benefit of design-time syntax checking of resource identifiers used in code.

Example:

C# CopyCode image Copy Code
MessageBox.Show(MyResources.LocalizedResourceIdentifier);

Unfortunately, the code generated by the default tool creates a standard system ResourceManager to retrieve the resources. For Smartsite applications, we’d like the auto-generated code to create a SmartsiteResourceManager instead, so the application will use custom resources instead of embedded resources if available.

Therefore, Smartsite applications should use a customized code generator called SmartsiteResXFileCodeGenerator. This tool generates strongly-typed resource classes that internally create a SmartsiteResourceManager.

To install the custom Smartsite code generator tool:

  • Copy the assembly SmartsiteResXFileCodeGenerator.dll to a local folder
  • Open a Visual Studio command prompt in the folder containing the assembly
  • Execute the command "regasm /codebase SmartsiteResXFileCodeGenerator.dll"
  • Restart Visual Studio

To use the custom Smartsite code generator:

  • Open a solution in Visual Studio 2005
  • Select the desired resx resource file in the Solution Explorer
  • Open the Property window for the selected resource file
  • Change the value of the Custom Tool property to SmartsiteResXFileCodeGenerator.
  • Right-click on the .resx resource file and select Run Custom Tool.

Now you can retrieve resource values in code by calling strongly-typed property functions, while still allowing a third-party developer to override and extend the embedded resources.