Rename TagClass to TagCollection

This commit is contained in:
Mbucari 2023-02-03 17:14:04 -07:00
parent 5917d059e4
commit 6f490b4491
6 changed files with 19 additions and 19 deletions

View File

@ -20,7 +20,7 @@ internal interface IClosingPropertyTag : IPropertyTag
bool StartsWithClosing(string templateString, out string exactName, out IClosingPropertyTag propertyTag);
}
public class ConditionalTagClass<TClass> : TagClass
public class ConditionalTagClass<TClass> : TagCollection
{
public ConditionalTagClass(bool caseSensative = true) :base(typeof(TClass), caseSensative) { }

View File

@ -16,7 +16,7 @@ public class NamingTemplate
private Delegate templateToString;
private readonly List<string> warnings = new();
private readonly List<string> errors = new();
private readonly IEnumerable<TagClass> Classes;
private readonly IEnumerable<TagCollection> Classes;
private readonly List<ITemplateTag> _tagsInUse = new();
public const string ERROR_NULL_IS_INVALID = "Null template is invalid.";
@ -47,9 +47,9 @@ public class NamingTemplate
/// <summary>Parse a template string to a <see cref="NamingTemplate"/></summary>
/// <param name="template">The template string to parse</param>
/// <param name="tagClasses">A collection of <see cref="TagClass"/> with
/// <param name="tagClasses">A collection of <see cref="TagCollection"/> with
/// properties registered to match to the <paramref name="template"/></param>
public static NamingTemplate Parse(string template, IEnumerable<TagClass> tagClasses)
public static NamingTemplate Parse(string template, IEnumerable<TagCollection> tagClasses)
{
var namingTemplate = new NamingTemplate(tagClasses);
try
@ -71,7 +71,7 @@ public class NamingTemplate
return namingTemplate;
}
private NamingTemplate(IEnumerable<TagClass> properties)
private NamingTemplate(IEnumerable<TagCollection> properties)
{
Classes = properties;
}

View File

@ -7,7 +7,7 @@ namespace FileManager.NamingTemplate;
public delegate string PropertyFormatter<T>(ITemplateTag templateTag, T value, string formatString);
public class PropertyTagClass<TClass> : TagClass
public class PropertyTagClass<TClass> : TagCollection
{
public PropertyTagClass(bool caseSensative = true) : base(typeof(TClass), caseSensative) { }

View File

@ -8,17 +8,17 @@ using System.Text.RegularExpressions;
namespace FileManager.NamingTemplate;
/// <summary>A collection of <see cref="IPropertyTag"/>s registered to a single <see cref="Type"/>.</summary>
public abstract class TagClass : IEnumerable<ITemplateTag>
public abstract class TagCollection : IEnumerable<ITemplateTag>
{
/// <summary>The <see cref="ParameterExpression"/> of the <see cref="TagClass"/>'s TClass type.</summary>
/// <summary>The <see cref="ParameterExpression"/> of the <see cref="TagCollection"/>'s TClass type.</summary>
public ParameterExpression Parameter { get; }
/// <summary>The <see cref="ITemplateTag"/>s registered with this <see cref="TagClass"/> </summary>
/// <summary>The <see cref="ITemplateTag"/>s registered with this <see cref="TagCollection"/> </summary>
public IEnumerator<ITemplateTag> GetEnumerator() => PropertyTags.Select(p => p.TemplateTag).GetEnumerator();
protected RegexOptions Options { get; } = RegexOptions.Compiled;
private List<IPropertyTag> PropertyTags { get; } = new();
protected TagClass(Type classType, bool caseSensative = true)
protected TagCollection(Type classType, bool caseSensative = true)
{
Parameter = Expression.Parameter(classType, classType.Name);
Options |= caseSensative ? RegexOptions.None : RegexOptions.IgnoreCase;

View File

@ -225,19 +225,19 @@ namespace LibationFileManager
},
new PropertyTagClass<MultiConvertFileProperties>()
{
{ TemplateTags.ChCount, lb => lb.PartsTotal, IntegerFormatter },
{ TemplateTags.ChNumber, lb => lb.PartsPosition, IntegerFormatter },
{ TemplateTags.ChCount, m => m.PartsTotal, IntegerFormatter },
{ TemplateTags.ChNumber, m => m.PartsPosition, IntegerFormatter },
{ TemplateTags.ChNumber0, m => m.PartsPosition.ToString("D" + ((int)Math.Log10(m.PartsTotal) + 1)) },
{ TemplateTags.ChTitle, m => m.Title, StringFormatter },
{ TemplateTags.FileDate, lb => lb.FileDate, DateTimeFormatter }
{ TemplateTags.FileDate, m => m.FileDate, DateTimeFormatter }
}
};
private static readonly ConditionalTagClass<LibraryBookDto> conditionalTags = new()
{
{TemplateTags.IfSeries, lb => lb.IsSeries },
{TemplateTags.IfPodcast, lb => lb.IsPodcast },
{TemplateTags.IfBookseries, lb => lb.IsSeries && !lb.IsPodcast },
{ TemplateTags.IfSeries, lb => lb.IsSeries },
{ TemplateTags.IfPodcast, lb => lb.IsPodcast },
{ TemplateTags.IfBookseries, lb => lb.IsSeries && !lb.IsPodcast },
};
#endregion

View File

@ -116,7 +116,7 @@ namespace NamingTemplateTests
[DataRow("<!ifc2-><ifc1-><ifc3-><item1><item4><item3_2><-ifc3><-ifc1><-ifc2>", "prop1_item1prop2_item4prop3_item2", 3)]
public void test(string inStr, string outStr, int numTags)
{
var template = NamingTemplate.Parse(inStr, new TagClass[] { props1, props2, props3, conditional1, conditional2, conditional3 });
var template = NamingTemplate.Parse(inStr, new TagCollection[] { props1, props2, props3, conditional1, conditional2, conditional3 });
template.TagsInUse.Should().HaveCount(numTags);
template.Warnings.Should().HaveCount(numTags > 0 ? 0 : 1);
@ -138,7 +138,7 @@ namespace NamingTemplateTests
[DataRow("<ifc2-><ifc1-><ifc3-><item1><item4><item3_2><-ifc1><-ifc2>", new string[] { "Missing <-ifc3> closing conditional.", "Missing <-ifc3> closing conditional.", "Missing <-ifc1> closing conditional.", "Missing <-ifc2> closing conditional." })]
public void condition_error(string inStr, string[] warnings)
{
var template = NamingTemplate.Parse(inStr, new TagClass[] { props1, props2, props3, conditional1, conditional2, conditional3 });
var template = NamingTemplate.Parse(inStr, new TagCollection[] { props1, props2, props3, conditional1, conditional2, conditional3 });
template.Errors.Should().HaveCount(0);
template.Warnings.Should().BeEquivalentTo(warnings);
@ -165,7 +165,7 @@ namespace NamingTemplateTests
props3.Add(new TemplateTag { TagName = "item3_format" }, i => i.Item3, formatString);
props2.Add(new TemplateTag { TagName = "item2_2_null" }, i => i.Item2, formatString);
var template = NamingTemplate.Parse(inStr, new TagClass[] { props1, props2, props3, conditional1, conditional2, conditional3 });
var template = NamingTemplate.Parse(inStr, new TagCollection[] { props1, props2, props3, conditional1, conditional2, conditional3 });
template.Warnings.Should().HaveCount(0);
template.Errors.Should().HaveCount(0);