add culture based caching

This commit is contained in:
2023-05-20 11:30:33 +00:00
parent 49e16a8077
commit 5a13431603
19 changed files with 186 additions and 55 deletions

View File

@@ -13,6 +13,7 @@ public class LogicResourcesTests
Assert.AreEqual(
new FormattedResourceString(
Properties.Resources.ResourceStringMembers.Format,
default,
LiteralString.Factory("ResourceStringMembers"),
LiteralString.Factory("ResourceManager")
).Value,
@@ -31,6 +32,7 @@ public class LogicResourcesTests
Assert.AreEqual(
new FormattedResourceString(
Properties.Resources.ResourceFormatClassMembers.Format,
default,
LiteralString.Factory("ResourceFormatClassMembers"),
LiteralString.Factory("ResourceManager"),
LiteralString.Factory("Format")
@@ -51,6 +53,7 @@ public class LogicResourcesTests
Assert.AreEqual(
new FormattedResourceString(
Properties.Resources.ResourceFormatClassFromMethod.Format,
default,
LiteralString.Factory("IResourceString name"),
LiteralString.Factory("name")
).Value,

View File

@@ -45,13 +45,23 @@ namespace TestNameSpace
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
#region Test1
private static readonly Lazy<IResourceString> LazyTest1 = new Lazy<IResourceString>(
() => new ResourceManagerString(""Test1"", ResourceManager, CultureInfo.CurrentCulture),
() => AddToCultureCache(new ResourceManagerString(""Test1"", ResourceManager, GetDefaultCulture)),
LazyThreadSafetyMode.PublicationOnly
);
@@ -62,17 +72,18 @@ namespace TestNameSpace
internal static class Test2
{
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
() => new ResourceManagerString(""Test2"", ResourceManager, CultureInfo.CurrentCulture),
() => AddToCultureCache(new ResourceManagerString(""Test2"", ResourceManager, GetDefaultCulture)),
LazyThreadSafetyMode.PublicationOnly
);
public static IResourceString Format => LazyFormat.Value;
public static IResourceString From(IResourceString prefix, IResourceString p1) => new FormattedResourceString(
public static IResourceString From(IResourceString prefix, IResourceString p1) => AddToCultureCache(new FormattedResourceString(
Format,
GetDefaultCulture,
prefix,
p1
);
));
}