I originally wrote the resource generator to run off a .resx file, but I’ve now updated the tools with two important changes. You can download the source from here, or the installer from here:
Firstly, there is now a command line .exe, SRGenerator.exe, which can be used by doing the following command line:
SRGenerator.exe <codeProvider> <namespace> <file>
codeProvider vb, cs, or CodeDom Provider assembly qualified class name.
namespace Namespace.
file File name, either a .strings file or a .resx file.
Secondly, the tool can now p*** the SR.strings file, which is the one of the string resource file format used within Microsoft. It will generate a SR.resx file, and the SR class to use the resource. This means that if you want to edit the enterprise library resources, just run this installer, and then you can edit the library to your hearts content.
The changes to the tool are the following:
It registers itself under both the SRCodeGen custom tool (my original name), and the StringResourceTool (used in the enterprise library source).
If the file that the custom tool is set on is not a resource file then it converts the file (in the format of the SR.strings file) into a resource file, and adds the file to the project underneath the .strings file, by doing the following:
1. Converts all options into resource file headers, e.g. #! culture_info = Resources.CultureInfo, becomes a header named “culture_info”, and with the value “Resources.CultureInfo”.
2. Converts all entries in the [strings] section into resources, with the name of the resource being the first part of the line, the value of the resource the part after the = sign, and the comment of the resource being anything in brackets after the name.
The resource file is then processed according to the rules of my original post, with a couple of changes:
· The comments denote the parameter names and optionally types of any arguments in the value (given as String.Format arguments). If there are no argument names specified in the comment, then the resource accessor generated will not use String.Format to replace any parameters in the resource. This allows having resources with un-replaced positional specifiers in them.
· The following options (specified as resource headers) are implemented:
i. culture_info : If specified, then this will be copied verbatim into the generated file as part of the call to ResourceManager.GetString(name, …). If not specified, then a public static Culture property is added to the SR class to allow changing the culture manually.
ii. accessor_class_accessibility: If this value is “public”, then the SR class will be public, otherwise it will be internal.
This uses CodeDOM, and so supports VB.NET as well as C#.