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('.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user