add version 0.0.1
This commit is contained in:
@@ -9,13 +9,10 @@ internal static class CodeSnippetFactory
|
||||
{
|
||||
public static IResourceString CreateResourceMangerMemberCodeSnippet(string typeName)
|
||||
{
|
||||
var formatString = Properties.Resources.ResourceManagerMemberTemplate;
|
||||
return new FormattableResourceString(
|
||||
formatString,
|
||||
return Properties.Resources.ResourceManagerMemberTemplate.From(
|
||||
LiteralString.Factory(typeName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static IEnumerable<IResourceString> CreateMemberCodeSnippets(IEnumerable<Resource> resources)
|
||||
{
|
||||
@@ -35,12 +32,63 @@ internal static class CodeSnippetFactory
|
||||
return Enumerable.Empty<IResourceString>();
|
||||
}
|
||||
|
||||
var formatString = Properties.Resources.ResourceStringMembers;
|
||||
return resources.Select(r => new FormattableResourceString(
|
||||
formatString,
|
||||
LiteralString.Factory(r.Name),
|
||||
resourceManagerName
|
||||
var stringResourses = resources.Where(r => r.Type.Match(
|
||||
v => typeof(string).IsAssignableFrom(Type.GetType(v.Trim(), false, true)),
|
||||
() => true
|
||||
));
|
||||
|
||||
return stringResourses.Select(r =>
|
||||
{
|
||||
var openBraces = r.Value
|
||||
.Replace("{{", string.Empty)
|
||||
.Replace("{{", string.Empty)
|
||||
.Split('{')
|
||||
.Skip(1)
|
||||
.ToArray();
|
||||
|
||||
if (openBraces.Any())
|
||||
{
|
||||
var formatNames = new System.Collections.Generic.HashSet<string>(
|
||||
openBraces.Select(b => b.Split('}').First())
|
||||
);
|
||||
|
||||
var resolveParameterNames = r.Comment.Match(
|
||||
c => c.Split(',')
|
||||
.Select(str => str.Split('='))
|
||||
.Where(parts => parts.Count() == 2)
|
||||
.Select(parts => (
|
||||
parts.First().Trim().Trim('{', '}').Split(' ').First(),
|
||||
parts.Last().Trim().Split(' ').First()
|
||||
)).Where(t => uint.TryParse(t.Item1, out var _))
|
||||
.GroupBy(t => t.Item1)
|
||||
.ToDictionary(k => k.Key, v => v.First().Item2),
|
||||
() => new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
var parameterNames = formatNames.Select(
|
||||
n => resolveParameterNames.TryGetValue(n.Trim(), out var paramName)
|
||||
? paramName.Substring(0, 1).ToLower() + paramName.Substring(1)
|
||||
: uint.TryParse(n, out var value) ? $"p{value + 1}" : n
|
||||
).ToArray();
|
||||
|
||||
var from = Properties.Resources.ResourceFormatClassFromMethod.From(
|
||||
new JoinedResourceString(
|
||||
LiteralString.Factory(", "),
|
||||
parameterNames.Select(n => LiteralString.Factory($"{nameof(IResourceString)} {n}")).ToArray()
|
||||
),
|
||||
new JoinedResourceString(
|
||||
LiteralString.Factory($",{System.Environment.NewLine} "),
|
||||
parameterNames.Select(n => LiteralString.Factory($"{n}")).ToArray()
|
||||
)
|
||||
);
|
||||
return Properties.Resources.ResourceFormatClassMembers.From(
|
||||
LiteralString.Factory(r.Name), resourceManagerName, from
|
||||
);
|
||||
}
|
||||
return Properties.Resources.ResourceStringMembers.From(
|
||||
LiteralString.Factory(r.Name), resourceManagerName
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public static IResourceString CreateResourceClassCodeSnippet(
|
||||
@@ -50,11 +98,9 @@ internal static class CodeSnippetFactory
|
||||
IEnumerable<IResourceString> memberSnippets
|
||||
)
|
||||
{
|
||||
var formatString = Properties.Resources.ResourcesClassTemplate;
|
||||
return new FormattableResourceString(
|
||||
formatString,
|
||||
return Properties.Resources.ResourcesClassTemplate.From(
|
||||
LiteralString.Factory(namespaceString),
|
||||
LiteralString.Factory(resourceClassName),
|
||||
LiteralString.Factory(resourceClassName),
|
||||
resourceManagerSnippet,
|
||||
new JoinedResourceString(
|
||||
LiteralString.Empty,
|
||||
@@ -63,12 +109,12 @@ internal static class CodeSnippetFactory
|
||||
);
|
||||
}
|
||||
|
||||
public static IResourceString CreateResourceClassCodeSnippet(
|
||||
string namespaceString,
|
||||
string resourceClassName,
|
||||
IResourceString resourceManagerSnippet,
|
||||
IEnumerable<Resource> resources
|
||||
)
|
||||
public static IResourceString CreateResourceClassCodeSnippet(
|
||||
string namespaceString,
|
||||
string resourceClassName,
|
||||
IResourceString resourceManagerSnippet,
|
||||
IEnumerable<Resource> resources
|
||||
)
|
||||
{
|
||||
return CreateResourceClassCodeSnippet(
|
||||
namespaceString,
|
||||
|
||||
Reference in New Issue
Block a user