fix resource class name generation -> 0.0.3
This commit is contained in:
@@ -2,15 +2,19 @@ using ResourceString.Net.Logic.DomainObjects.Resx;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ResourceString.Net.Logic.Factories;
|
||||
|
||||
internal static class CodeSnippetFactory
|
||||
{
|
||||
public static IResourceString CreateResourceMangerMemberCodeSnippet(string typeName)
|
||||
public static IResourceString CreateResourceMangerMemberCodeSnippet(
|
||||
string resourceName,
|
||||
string className)
|
||||
{
|
||||
return Properties.Resources.ResourceManagerMemberTemplate.From(
|
||||
LiteralString.Factory(typeName)
|
||||
LiteralString.Factory(resourceName),
|
||||
LiteralString.Factory(className)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,8 +28,7 @@ internal static class CodeSnippetFactory
|
||||
|
||||
public static IEnumerable<IResourceString> CreateMemberCodeSnippets(
|
||||
IEnumerable<Resource> resources,
|
||||
IResourceString resourceManagerName
|
||||
)
|
||||
IResourceString resourceManagerName)
|
||||
{
|
||||
if (resources is null)
|
||||
{
|
||||
@@ -95,8 +98,7 @@ internal static class CodeSnippetFactory
|
||||
string namespaceString,
|
||||
string resourceClassName,
|
||||
IResourceString resourceManagerSnippet,
|
||||
IEnumerable<IResourceString> memberSnippets
|
||||
)
|
||||
IEnumerable<IResourceString> memberSnippets)
|
||||
{
|
||||
return Properties.Resources.ResourcesClassTemplate.From(
|
||||
LiteralString.Factory(namespaceString),
|
||||
@@ -123,4 +125,28 @@ internal static class CodeSnippetFactory
|
||||
CreateMemberCodeSnippets(resources)
|
||||
);
|
||||
}
|
||||
|
||||
public static string TransformToClassName(string input)
|
||||
{
|
||||
// Remove invalid characters and replace them with underscores
|
||||
string sanitizedInput = Regex.Replace(
|
||||
input?.Trim() ?? string.Empty,
|
||||
@"[^a-zA-Z0-9_]", "_"
|
||||
);
|
||||
|
||||
// Remove leading digits if the string starts with a digit
|
||||
return Regex.Replace(sanitizedInput, @"^\d+", "");
|
||||
}
|
||||
|
||||
public static string TransformToNamespace(string input)
|
||||
{
|
||||
// Remove invalid characters and replace them with dots
|
||||
string sanitizedInput = Regex.Replace(
|
||||
input?.Trim() ?? string.Empty,
|
||||
@"[^a-zA-Z0-9_.]", "."
|
||||
);
|
||||
|
||||
// Remove leading dots if present
|
||||
return sanitizedInput.TrimStart('.');
|
||||
}
|
||||
}
|
||||
@@ -12,18 +12,18 @@ namespace ResourceString.Net.Logic.Properties
|
||||
#region ResourceManager
|
||||
|
||||
private static readonly Type _Type = typeof(Resources);
|
||||
|
||||
|
||||
private static readonly Lazy<ResourceManager> _ResourceManager = new Lazy<ResourceManager>(
|
||||
() => new ResourceManager(_Type.FullName ?? string.Empty, _Type.Assembly),
|
||||
() => new ResourceManager("ResourceString.Net.Logic.Properties.Resources" ?? string.Empty, _Type.Assembly),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
public static ResourceManager ResourceManager => _ResourceManager.Value;
|
||||
|
||||
#endregion // ResourceManager
|
||||
|
||||
|
||||
internal static class ResourceStringMembers
|
||||
|
||||
internal static class ResourceStringMembers
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourceStringMembers", ResourceManager, CultureInfo.CurrentCulture),
|
||||
@@ -31,16 +31,16 @@ namespace ResourceString.Net.Logic.Properties
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
|
||||
public static IResourceString From(IResourceString resourceId, IResourceString resourceManagerPropertyName) => new FormattedResourceString(
|
||||
Format,
|
||||
Format,
|
||||
resourceId,
|
||||
resourceManagerPropertyName
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceFormatClassMembers
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceFormatClassMembers
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourceFormatClassMembers", ResourceManager, CultureInfo.CurrentCulture),
|
||||
@@ -48,17 +48,17 @@ namespace ResourceString.Net.Logic.Properties
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
|
||||
public static IResourceString From(IResourceString resourceId, IResourceString resourceManagerPropertyName, IResourceString fromMethodDefinition) => new FormattedResourceString(
|
||||
Format,
|
||||
Format,
|
||||
resourceId,
|
||||
resourceManagerPropertyName,
|
||||
fromMethodDefinition
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceFormatClassFromMethod
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceFormatClassFromMethod
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourceFormatClassFromMethod", ResourceManager, CultureInfo.CurrentCulture),
|
||||
@@ -66,16 +66,16 @@ namespace ResourceString.Net.Logic.Properties
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
|
||||
public static IResourceString From(IResourceString fromMethodSignature, IResourceString parameterNames) => new FormattedResourceString(
|
||||
Format,
|
||||
Format,
|
||||
fromMethodSignature,
|
||||
parameterNames
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourcesClassTemplate
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourcesClassTemplate
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourcesClassTemplate", ResourceManager, CultureInfo.CurrentCulture),
|
||||
@@ -83,18 +83,18 @@ namespace ResourceString.Net.Logic.Properties
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
|
||||
public static IResourceString From(IResourceString ns, IResourceString className, IResourceString resourceManagerRegion, IResourceString resourceRegions) => new FormattedResourceString(
|
||||
Format,
|
||||
Format,
|
||||
ns,
|
||||
className,
|
||||
resourceManagerRegion,
|
||||
resourceRegions
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceManagerMemberTemplate
|
||||
|
||||
}
|
||||
|
||||
internal static class ResourceManagerMemberTemplate
|
||||
{
|
||||
private static readonly Lazy<IResourceString> LazyFormat = new Lazy<IResourceString>(
|
||||
() => new ResourceManagerString("ResourceManagerMemberTemplate", ResourceManager, CultureInfo.CurrentCulture),
|
||||
@@ -102,14 +102,15 @@ namespace ResourceString.Net.Logic.Properties
|
||||
);
|
||||
|
||||
public static IResourceString Format => LazyFormat.Value;
|
||||
|
||||
public static IResourceString From(IResourceString resourceManagerTypeName) => new FormattedResourceString(
|
||||
Format,
|
||||
|
||||
public static IResourceString From(IResourceString className, IResourceString resourceManagerTypeName) => new FormattedResourceString(
|
||||
Format,
|
||||
className,
|
||||
resourceManagerTypeName
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#region DefaultPropertyName_ResourceManager
|
||||
|
||||
private static readonly Lazy<IResourceString> LazyDefaultPropertyName_ResourceManager = new Lazy<IResourceString>(
|
||||
@@ -120,6 +121,6 @@ namespace ResourceString.Net.Logic.Properties
|
||||
public static IResourceString DefaultPropertyName_ResourceManager => LazyDefaultPropertyName_ResourceManager.Value;
|
||||
|
||||
#endregion // DefaultPropertyName_ResourceManager
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,10 +62,10 @@ namespace {0}
|
||||
<value>
|
||||
#region ResourceManager
|
||||
|
||||
private static readonly Type _Type = typeof({0});
|
||||
private static readonly Type _Type = typeof({1});
|
||||
|
||||
private static readonly Lazy<ResourceManager> _ResourceManager = new Lazy<ResourceManager>(
|
||||
() => new ResourceManager(_Type.FullName ?? string.Empty, _Type.Assembly),
|
||||
() => new ResourceManager("{0}" ?? string.Empty, _Type.Assembly),
|
||||
LazyThreadSafetyMode.PublicationOnly
|
||||
);
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace {0}
|
||||
|
||||
#endregion // ResourceManager
|
||||
</value>
|
||||
<comment>0 = ResourceManagerTypeName</comment>
|
||||
<comment>0 = ResourceManagerTypeName, 1 = ClassName</comment>
|
||||
</data>
|
||||
<data name="DefaultPropertyName_ResourceManager">
|
||||
<value>ResourceManager</value>
|
||||
|
||||
Reference in New Issue
Block a user