-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate extension-methods for classic ResXFileCodeGenerator types #23
Comments
Closing, as the generated types only contain static-properties, which cannot be extended in a way that actually make sense. Also, using these types should be avoided, as they tend to be problematic in multi-threaded(-multi-cultured) apps, due to their nature of heavily relying on those statics. People should find a way to introduce the usage of Maybe a FAQ could help people in guiding theit way to adopt |
Recently revisited possibilities to support this based on this discussions over at #78.
<root>
<data name="Greeting" xml:space="preserve">
<value>Cheers!</value>
</data>
<data name="Hello {world:s}" xml:space="preserve">
<value>Hello '{0}'</value>
</data>
</root>
internal class SamplesWithCode {
//other stuff ommited for simplicity
/// <summary>
/// Looks up a localized string similar to Cheers!.
/// </summary>
internal static string Greeting {
get {
return ResourceManager.GetString("Greeting", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Hello '{0}'.
/// </summary>
internal static string Hello__world_s_ {
get {
return ResourceManager.GetString("Hello {world:s}", resourceCulture);
}
}
} A feasable approach could be to generate the following code for a
internal static class SamplesWithCodeExtensions
{
static LocalizedString GetLocalizable(string key, params object[] args)
{
var value = key;
var raw = SamplesWithCode.ResourceManager.GetString(key, SamplesWithCode.Culture);
if (raw is not null)
{
value = raw;
}
var formattedValue = string.Format(value, args);
return new LocalizedString(key, formattedValue, raw is null);
}
public static LocalizedString Hello__world(this SamplesWithCode _, string world)
=> GetLocalizable("Hello {world:s}", world);
public static LocalizedString Greeting(this SamplesWithCode _)
=> GetLocalizable("Greeting");
} Which then could be used as: var x = new SamplesWithCode(); //generated class by *ResXFileCodeGenerator
Console.WriteLine(x.Greeting()); // generated by TypealizR
Console.WriteLine(x.Hello__world("earth")); // generated by TypealizR The key here is to use the type generated by |
Maybe the generated methods need an additional |
As a developer, I want the
source-generator
to generate typed extension-methods for already existing types that are generated by the classic ResXFileGenerator``, in order to leverage typed access to interpolated ressources.The text was updated successfully, but these errors were encountered: