add culture based caching -> 0.0.4
This commit is contained in:
@@ -35,12 +35,12 @@ internal static class CodeSnippetFactory
|
||||
return Enumerable.Empty<IResourceString>();
|
||||
}
|
||||
|
||||
var stringResourses = resources.Where(r => r.Type.Match(
|
||||
var stringResources = resources.Where(r => r.Type.Match(
|
||||
v => typeof(string).IsAssignableFrom(Type.GetType(v.Trim(), false, true)),
|
||||
() => true
|
||||
));
|
||||
|
||||
return stringResourses.Select(r =>
|
||||
return stringResources.Select(r =>
|
||||
{
|
||||
var openBraces = r.Value
|
||||
.Replace("{{", string.Empty)
|
||||
@@ -77,11 +77,11 @@ internal static class CodeSnippetFactory
|
||||
var from = Properties.Resources.ResourceFormatClassFromMethod.From(
|
||||
new JoinedResourceString(
|
||||
LiteralString.Factory(", "),
|
||||
parameterNames.Select(n => LiteralString.Factory($"{nameof(IResourceString)} {n}")).ToArray()
|
||||
elements: parameterNames.Select(n => LiteralString.Factory($"{nameof(IResourceString)} {n}")).ToArray()
|
||||
),
|
||||
new JoinedResourceString(
|
||||
LiteralString.Factory($",{System.Environment.NewLine} "),
|
||||
parameterNames.Select(n => LiteralString.Factory($"{n}")).ToArray()
|
||||
elements: parameterNames.Select(n => LiteralString.Factory($"{n}")).ToArray()
|
||||
)
|
||||
);
|
||||
return Properties.Resources.ResourceFormatClassMembers.From(
|
||||
@@ -106,7 +106,7 @@ internal static class CodeSnippetFactory
|
||||
resourceManagerSnippet,
|
||||
new JoinedResourceString(
|
||||
LiteralString.Empty,
|
||||
memberSnippets?.ToArray() ?? Array.Empty<IResourceString>()
|
||||
elements: memberSnippets?.ToArray() ?? Array.Empty<IResourceString>()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,101 +20,116 @@ namespace ResourceString.Net.Logic.Properties
|
||||
|
||||
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
|
||||
|
||||
|
||||
internal static class ResourceStringMembers
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourceStringMembers", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("ResourceStringMembers", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString resourceId, IResourceString resourceManagerPropertyName) => new FormattedResourceString(
|
||||
public static IResourceString From(IResourceString resourceId, IResourceString resourceManagerPropertyName) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
GetDefaultCulture,
|
||||
resourceId,
|
||||
resourceManagerPropertyName
|
||||
);
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceFormatClassMembers
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourceFormatClassMembers", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("ResourceFormatClassMembers", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString resourceId, IResourceString resourceManagerPropertyName, IResourceString fromMethodDefinition) => new FormattedResourceString(
|
||||
public static IResourceString From(IResourceString resourceId, IResourceString resourceManagerPropertyName, IResourceString fromMethodDefinition) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
GetDefaultCulture,
|
||||
resourceId,
|
||||
resourceManagerPropertyName,
|
||||
fromMethodDefinition
|
||||
);
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceFormatClassFromMethod
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourceFormatClassFromMethod", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("ResourceFormatClassFromMethod", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString fromMethodSignature, IResourceString parameterNames) => new FormattedResourceString(
|
||||
public static IResourceString From(IResourceString fromMethodSignature, IResourceString parameterNames) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
GetDefaultCulture,
|
||||
fromMethodSignature,
|
||||
parameterNames
|
||||
);
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourcesClassTemplate
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourcesClassTemplate", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("ResourcesClassTemplate", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString ns, IResourceString className, IResourceString resourceManagerRegion, IResourceString resourceRegions) => new FormattedResourceString(
|
||||
public static IResourceString From(IResourceString ns, IResourceString className, IResourceString resourceManagerRegion, IResourceString resourceRegions) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
GetDefaultCulture,
|
||||
ns,
|
||||
className,
|
||||
resourceManagerRegion,
|
||||
resourceRegions
|
||||
);
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceManagerMemberTemplate
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourceManagerMemberTemplate", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("ResourceManagerMemberTemplate", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString className, IResourceString resourceManagerTypeName) => new FormattedResourceString(
|
||||
public static IResourceString From(IResourceString className, IResourceString resourceManagerTypeName) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
GetDefaultCulture,
|
||||
className,
|
||||
resourceManagerTypeName
|
||||
);
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
#region DefaultPropertyName_ResourceManager
|
||||
|
||||
private static readonly Lazy<IResourceString> LazyDefaultPropertyName_ResourceManager = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("DefaultPropertyName_ResourceManager", ResourceManager, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("DefaultPropertyName_ResourceManager", ResourceManager, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#region {0}
|
||||
|
||||
private static readonly Lazy<IResourceString> Lazy{0} = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("{0}", {1}, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("{0}", {1}, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
internal static class {0}
|
||||
{{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("{0}", {1}, CultureInfo.CurrentCulture),
|
||||
() => AddToCultureCache(new ResourceManagerString("{0}", {1}, GetDefaultCulture)),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
@@ -32,10 +32,11 @@
|
||||
</data>
|
||||
<data name="ResourceFormatClassFromMethod" xml:space="preserve">
|
||||
<value>
|
||||
public static IResourceString From({0}) => new FormattedResourceString(
|
||||
public static IResourceString From({0}) => AddToCultureCache(new FormattedResourceString(
|
||||
Format,
|
||||
GetDefaultCulture,
|
||||
{1}
|
||||
);
|
||||
));
|
||||
</value>
|
||||
<comment>0 = FromMethodSignature, 1 = ParameterNames</comment>
|
||||
</data>
|
||||
@@ -71,6 +72,16 @@ namespace {0}
|
||||
|
||||
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
|
||||
</value>
|
||||
<comment>0 = ResourceManagerTypeName, 1 = ClassName</comment>
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<Deterministic>true</Deterministic>
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LanguageExt.Core" Version="4.4.3" />
|
||||
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
|
||||
|
||||
Reference in New Issue
Block a user