add culture based caching
This commit is contained in:
39
Readme.md
39
Readme.md
@@ -93,6 +93,16 @@ namespace MyTestConsoleApp
|
||||
);
|
||||
|
||||
public static ResourceManager ResourceManager => _ResourceManager.Value;
|
||||
|
||||
private static CultureInfo GetDefaultCulture()
|
||||
{
|
||||
return CultureInfo.CurrentCulture;
|
||||
}
|
||||
|
||||
private static IResourceString AddToCultureCache(IResourceString source)
|
||||
{
|
||||
return new CultureBasedCachedString(source, GetDefaultCulture);
|
||||
}
|
||||
|
||||
#endregion // ResourceManager
|
||||
|
||||
@@ -101,16 +111,17 @@ namespace MyTestConsoleApp
|
||||
internal static class Greetings
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("Greetings", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("Greetings", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString name) => new FormattedResourceString(
|
||||
public static IResourceString From(IResourceString name) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
GetDefaultCulture,
|
||||
name
|
||||
);
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
@@ -119,7 +130,7 @@ namespace MyTestConsoleApp
|
||||
#region World
|
||||
|
||||
private static readonly Lazy<IResourceString> LazyWorld = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("World", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("World", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
@@ -181,7 +192,7 @@ the source code generator transforms it into the following `C#` class members:
|
||||
#region World
|
||||
|
||||
private static readonly Lazy<IResourceString> LazyWorld = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("World", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("World", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
@@ -206,17 +217,18 @@ the generator generates following code to support the formatted string:
|
||||
internal static class Greetings
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("Greetings", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("Greetings", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString p1, IResourceString p2) => new FormattedResourceString(
|
||||
Format,
|
||||
public static IResourceString From(IResourceString p1, IResourceString p2) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
GetDefaultCulture,
|
||||
p1,
|
||||
p2
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
#endregion // Greetings
|
||||
@@ -234,11 +246,11 @@ In cases where the element with the format string includes a comment element lik
|
||||
the source generator extracts the parameter names from the comment instead of using generic names:
|
||||
|
||||
```cs
|
||||
public static IResourceString From(IResourceString name, IResourceString otherName) => new FormattedResourceString(
|
||||
public static IResourceString From(IResourceString name, IResourceString otherName) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
name,
|
||||
otherName
|
||||
);
|
||||
));
|
||||
```
|
||||
|
||||
This allows for more descriptive parameter names in the generated code.
|
||||
@@ -278,7 +290,10 @@ This allows for more descriptive parameter names in the generated code.
|
||||
- Provides access to resource strings stored in `resx` files or other resource sources.
|
||||
- Handles retrieving the localized value for the specified `CultureInfo`.
|
||||
|
||||
Great! Based on the provided code for the console app `ResourceString.Net.App.Console`, let's enhance the Readme.md file to include instructions on how to use the console app and generate a C# class based on a given resource file.
|
||||
### CultureBasedCachedString
|
||||
|
||||
- Implements the `IResourceString` interface.
|
||||
- Enhances performance by avoiding redundant resource string lookups and reducing the overhead associated with repeated string generation.
|
||||
|
||||
## Console App: ResourceString.Net.App.Console
|
||||
|
||||
|
||||
Reference in New Issue
Block a user