This package generates a static `ThisAssembly.Strings` class with public constants exposing string resources in .resx files or methods with the right number of parameters for strings that use formatting parameters. In addition, it groups constants and methods in nested classes according to an optional underscore separator to organize strings. For example, *User_InvalidCredentials* can be accessed with *ThisAssembly.Strings.User.InvalidCredentials* if it contains a simple string, or as a method with the right number of parametres if its value has a format string. Finally, format strings can use named parameters too to get more friendly parameter names, such as "Hello {name}".
$ dotnet add package ThisAssembly.StringsThis package generates a static ThisAssembly.Strings class with public
constants exposing string resources in .resx files or methods with the right number of
parameters for strings that use formatting parameters.

In addition, it groups constants and methods in nested classes according to an optional underscore separator to organize strings. For example, User_InvalidCredentials can be accessed with ThisAssembly.Strings.User.InvalidCredentials if it contains a simple string, or as a method with the right number of parametres if its value has a format string.
Given the following Resx file:
| Name | Value | Comment |
|---|---|---|
| Infrastructure_MissingService | Service {0} is required. | For logging only! |
| Shopping_NoShipping | We cannot ship {0} to {1}. | |
| Shopping_OutOfStock | Product is out of stock at this time. | |
| Shopping_AvailableOn | Product available on {date:yyyy-MM}. |
The following code would be generated:
partial class ThisAssembly
{
public static partial class Strings
{
public static partial class Infrastructure
{
/// <summary>
/// For logging only!
/// => "Service {0} is required."
/// </summary>
public static string MissingService(object arg0)
=> string.Format(CultureInfo.CurrentCulture,
Strings.GetResourceManager("ThisStore.Properties.Resources").GetString("MissingService"),
arg0);
}
public static partial class Shopping
{
/// <summary>
/// => "We cannot ship {0} to {1}."
/// </summary>
public static string NoShipping(object arg0, object arg1)
=> string.Format(CultureInfo.CurrentCulture,
Strings.GetResourceManager("ThisStore.Properties.Resources").GetString("NoShipping"),
arg0, arg1);
/// <summary>
/// => "Product is out of stock at this time."
/// </summary>
public static string OutOfStock
=> Strings.GetResourceManager("ThisStore.Properties.Resources").GetString("OutOfStock");
/// <summary>
/// Product available on {date:yyyy-MM}.
/// </summary>
public static string AvailableOn(object date)
=> string.Format(CultureInfo.CurrentCulture,
Strings.GetResourceManager("ThisAssemblyTests.Resources").GetString("WithNamedFormat").Replace("{date:yyyy-MM}", "{0}"),
((IFormattable)date).ToString("yyyy-MM", CultureInfo.CurrentCulture));
}
}
}The following MSBuild properties can be used to customize the generated code:
| Property | Description |
|---|---|
| ThisAssemblyNamespace | Sets the namespace of the generated ThisAssembly root class. If not set, it will be in the global namespace. |
| ThisAssemblyVisibility | Sets the visibility modifier of the generated ThisAssembly root class. If not set, it will be internal. |
To ensure the long-term sustainability of this project, users of this package who generate revenue must pay an Open Source Maintenance Fee. While the source code is freely available under the terms of the License, this package and other aspects of the project require adherence to the Maintenance Fee.
To pay the Maintenance Fee, become a Sponsor at the proper OSMF tier. A single fee covers all of Devlooped packages.