add culture based caching -> 0.0.4
This commit is contained in:
37
Readme.md
37
Readme.md
@@ -94,6 +94,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
|
||||
|
||||
#region Greetings
|
||||
@@ -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(
|
||||
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
|
||||
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
<PackAsTool>true</PackAsTool>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<Deterministic>true</Deterministic>
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../ResourceString.Net.Logic/ResourceString.Net.Logic.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
39
ResourceString.Net.Contract/CultureBasedCachedString.cs
Normal file
39
ResourceString.Net.Contract/CultureBasedCachedString.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace ResourceString.Net.Contract
|
||||
{
|
||||
public sealed class CultureBasedCachedString : IResourceString
|
||||
{
|
||||
private readonly Func<CultureInfo> m_GetDefaultCulture;
|
||||
|
||||
private readonly IResourceString m_ResourceString;
|
||||
|
||||
private readonly Dictionary<CultureInfo, string> m_Cache = new Dictionary<CultureInfo, string>();
|
||||
|
||||
public CultureBasedCachedString(
|
||||
IResourceString resourceString,
|
||||
Func<CultureInfo>? getDefaultCulture = default)
|
||||
{
|
||||
m_ResourceString = resourceString;
|
||||
m_GetDefaultCulture = getDefaultCulture ?? (() => CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
public string Value => GetValue(m_GetDefaultCulture());
|
||||
|
||||
public string GetValue(CultureInfo cultureInfo)
|
||||
{
|
||||
if (m_Cache.TryGetValue(cultureInfo, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
var newValue = m_ResourceString.GetValue(cultureInfo);
|
||||
m_Cache[cultureInfo] = newValue;
|
||||
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace ResourceString.Net.Contract
|
||||
{
|
||||
public class FormattedResourceString : IResourceString
|
||||
public sealed class FormattedResourceString : IResourceString
|
||||
{
|
||||
private readonly Func<CultureInfo> m_GetDefaultCulture;
|
||||
|
||||
public IResourceString Format { get; }
|
||||
|
||||
public IEnumerable<IResourceString> Parameters { get; }
|
||||
@@ -14,14 +17,17 @@ namespace ResourceString.Net.Contract
|
||||
|
||||
public FormattedResourceString(
|
||||
IResourceString format,
|
||||
Func<CultureInfo>? getDefaultCulture = default,
|
||||
params IResourceString[] parameters)
|
||||
{
|
||||
Format = format ?? new JoinedResourceString(
|
||||
LiteralString.Factory(","),
|
||||
getDefaultCulture,
|
||||
parameters.Select(((p, idx) => LiteralString.Factory("{" + idx + "}"))).ToArray()
|
||||
);
|
||||
|
||||
Parameters = parameters;
|
||||
m_GetDefaultCulture = getDefaultCulture ?? (() => CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
public string GetValue(CultureInfo cultureInfo)
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace ResourceString.Net.Contract
|
||||
{
|
||||
|
||||
public class JoinedResourceString : IResourceString
|
||||
public sealed class JoinedResourceString : IResourceString
|
||||
{
|
||||
private readonly Func<CultureInfo> m_GetDefaultCulture;
|
||||
|
||||
public IResourceString Separator { get; }
|
||||
|
||||
public IEnumerable<IResourceString> Elements { get; }
|
||||
@@ -15,6 +18,7 @@ namespace ResourceString.Net.Contract
|
||||
|
||||
public JoinedResourceString(
|
||||
IResourceString separator,
|
||||
Func<CultureInfo>? getDefaultCulture = default,
|
||||
params IResourceString[] elements)
|
||||
{
|
||||
Separator = separator ?? new LiteralString(
|
||||
@@ -22,6 +26,7 @@ namespace ResourceString.Net.Contract
|
||||
);
|
||||
|
||||
Elements = elements;
|
||||
m_GetDefaultCulture = getDefaultCulture ?? (() => CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
public string GetValue(CultureInfo cultureInfo)
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Threading;
|
||||
|
||||
namespace ResourceString.Net.Contract
|
||||
{
|
||||
public class LiteralString : IResourceString
|
||||
public sealed class LiteralString : IResourceString
|
||||
{
|
||||
private Lazy<string> m_Value;
|
||||
|
||||
|
||||
@@ -6,22 +6,22 @@ namespace ResourceString.Net.Contract
|
||||
{
|
||||
public class ResourceManagerString : IResourceString
|
||||
{
|
||||
private readonly CultureInfo m_Culture;
|
||||
private readonly Func<CultureInfo> m_GetDefaultCulture;
|
||||
|
||||
public string Id { get; }
|
||||
|
||||
public ResourceManager Manager { get; }
|
||||
|
||||
public string Value => GetValue(m_Culture);
|
||||
public string Value => GetValue(m_GetDefaultCulture());
|
||||
|
||||
public ResourceManagerString(
|
||||
string id,
|
||||
ResourceManager manager,
|
||||
CultureInfo cultureInfo)
|
||||
Func<CultureInfo>? getDefaultCulture = default)
|
||||
{
|
||||
Id = id ?? string.Empty;
|
||||
Manager = manager ?? throw new ArgumentNullException(nameof(manager));
|
||||
m_Culture = cultureInfo ?? CultureInfo.CurrentCulture;
|
||||
m_GetDefaultCulture = getDefaultCulture ?? (() => CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
public string GetValue(CultureInfo cultureInfo)
|
||||
|
||||
@@ -6,4 +6,9 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<Deterministic>true</Deterministic>
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
);
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -13,14 +13,26 @@
|
||||
<NoPackageAnalysis>true</NoPackageAnalysis>
|
||||
<IncludeBuildOutput>false</IncludeBuildOutput>
|
||||
<PackageProjectUrl>https://gitlab.com/stubbfel/ResourceString.Net</PackageProjectUrl>
|
||||
<RepositoryUrl>https://gitlab.com/stubbfel/ResourceString.Net.git</RepositoryUrl>
|
||||
<RepositoryBranch>main</RepositoryBranch>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageReadmeFile>Readme.md</PackageReadmeFile>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<Deterministic>true</Deterministic>
|
||||
<Optimize>true</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- It puts the dll in the expected folder of the NuGet package to be recognized as a C# analyzer -->
|
||||
<ItemGroup>
|
||||
<None Include="$(OutputPath)/*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||
<None Include="$(OutputPath)/$(AssemblyName).Contract.dll" Pack="true" PackagePath="lib/netstandard2.0" Visible="false" />
|
||||
<None Include="$(OutputPath)/$(AssemblyName).Contract.pdb" Pack="true" PackagePath="lib/netstandard2.0" Visible="false" />
|
||||
<None Include="../Readme.md" Pack="true" PackagePath="/"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
{ fetchNuGet }: [
|
||||
(fetchNuGet { pname = "Fody"; version = "6.7.0"; sha256 = "0fv0zrffa296qjyi11yk31vfqh6gm1nxsx8g5zz380jcsrilnp3h"; })
|
||||
(fetchNuGet { pname = "ILMerge.Fody"; version = "1.24.0"; sha256 = "1gibwcl8ngbvwlcqzd9clysrhsjb8g4gwry7n8ifw1mrw7sjjk6x"; })
|
||||
(fetchNuGet { pname = "LanguageExt.Core"; version = "4.4.3"; sha256 = "1pd7wx4c21v56y6i75sxbs990mjrs6bp9h8c48a5w79s1zpbinw5"; })
|
||||
(fetchNuGet { pname = "Microsoft.Bcl.AsyncInterfaces"; version = "7.0.0"; sha256 = "1waiggh3g1cclc81gmjrqbh128kwfjky3z79ma4bd2ms9pa3gvfm"; })
|
||||
(fetchNuGet { pname = "Microsoft.CodeAnalysis.Analyzers"; version = "3.3.4"; sha256 = "0wd6v57p53ahz5z9zg4iyzmy3src7rlsncyqpcag02jjj1yx6g58"; })
|
||||
|
||||
1
alias.sh
1
alias.sh
@@ -4,3 +4,4 @@ alias nixe='nix --experimental-features "nix-command flakes"'
|
||||
alias nulock='nixe run .#devTasks.updateNugetLock'
|
||||
alias fllock='nixe run .#devTasks.updateFlakeLock'
|
||||
alias ulock='nulock && fllock'
|
||||
alias restore-on-current-source='nixe build && dotnet nuget locals all -c && dotnet restore -s result/share -s https://api.nuget.org/v3/index.json $1'
|
||||
6
flake.lock
generated
6
flake.lock
generated
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1684364070,
|
||||
"narHash": "sha256-+bmqPSEQBePWwmfwxUX8kvJLyg8OM9mRKnDi5qB+m1s=",
|
||||
"lastModified": 1684522302,
|
||||
"narHash": "sha256-L7nUSrOYTWvXmIQ8NtVU2/AAah/ouJpf9DDVSt0s9+I=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2e6eb88c9ab70147e6087d37c833833fd4a907e5",
|
||||
"rev": "c555a28f2436be370c40df70f4cd6c25fceff7af",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
Reference in New Issue
Block a user