Introduction

edit

Meziantou.Framework.ResxSourceGenerator is a C# source generator for .resx resource files. For each file, it writes a class with a property for each resource, and, for each string that contains placeholders such as {0}, a method that formats it:

<data name="Hello" xml:space="preserve">
  <value>Hello {0}!</value>
</data>
Assert.Equal("Hello {0}!", Sample.Hello);
Assert.Equal("Hello meziantou!", Sample.FormatHello("meziantou"));

The generated class reads the resources from the assembly with a ResourceManager, so the localized .resx files (Sample.fr.resx...) work as usual. The class is regenerated when the .resx file changes, in the IDE as in the build, without a designer file to keep in sync.

What you can do with it

  • Read strings, files and objects with typed properties, and format the strings with typed methods. See Generated members.
  • Name and type the parameters of the format methods, and document them, in the .resx file. See Format parameters.
  • Choose the namespace, the class name and the visibility of each file. See Configuration.
  • Refer to resource names without string literals, with the generated Names class.

Next steps

  • Getting started: install the package and enable the generator for the .resx files.
  • Diagnostics: the warnings reported when a file cannot be processed.