From 6f490b44916a65c3c10154a1cd6ea4557eda98be Mon Sep 17 00:00:00 2001 From: Mbucari Date: Fri, 3 Feb 2023 17:14:04 -0700 Subject: [PATCH] Rename TagClass to TagCollection --- .../NamingTemplate/ConditionalTagClass[TClass].cs | 2 +- Source/FileManager/NamingTemplate/NamingTemplate.cs | 8 ++++---- .../NamingTemplate/PropertyTagClass[TClass].cs | 2 +- .../NamingTemplate/{TagClass.cs => TagCollection.cs} | 8 ++++---- Source/LibationFileManager/Templates.cs | 12 ++++++------ .../FileManager.Tests/FileNamingTemplateTests.cs | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) rename Source/FileManager/NamingTemplate/{TagClass.cs => TagCollection.cs} (93%) diff --git a/Source/FileManager/NamingTemplate/ConditionalTagClass[TClass].cs b/Source/FileManager/NamingTemplate/ConditionalTagClass[TClass].cs index da48b30f..bddfac26 100644 --- a/Source/FileManager/NamingTemplate/ConditionalTagClass[TClass].cs +++ b/Source/FileManager/NamingTemplate/ConditionalTagClass[TClass].cs @@ -20,7 +20,7 @@ internal interface IClosingPropertyTag : IPropertyTag bool StartsWithClosing(string templateString, out string exactName, out IClosingPropertyTag propertyTag); } -public class ConditionalTagClass : TagClass +public class ConditionalTagClass : TagCollection { public ConditionalTagClass(bool caseSensative = true) :base(typeof(TClass), caseSensative) { } diff --git a/Source/FileManager/NamingTemplate/NamingTemplate.cs b/Source/FileManager/NamingTemplate/NamingTemplate.cs index a3884123..1de60531 100644 --- a/Source/FileManager/NamingTemplate/NamingTemplate.cs +++ b/Source/FileManager/NamingTemplate/NamingTemplate.cs @@ -16,7 +16,7 @@ public class NamingTemplate private Delegate templateToString; private readonly List warnings = new(); private readonly List errors = new(); - private readonly IEnumerable Classes; + private readonly IEnumerable Classes; private readonly List _tagsInUse = new(); public const string ERROR_NULL_IS_INVALID = "Null template is invalid."; @@ -47,9 +47,9 @@ public class NamingTemplate /// Parse a template string to a /// The template string to parse - /// A collection of with + /// A collection of with /// properties registered to match to the - public static NamingTemplate Parse(string template, IEnumerable tagClasses) + public static NamingTemplate Parse(string template, IEnumerable tagClasses) { var namingTemplate = new NamingTemplate(tagClasses); try @@ -71,7 +71,7 @@ public class NamingTemplate return namingTemplate; } - private NamingTemplate(IEnumerable properties) + private NamingTemplate(IEnumerable properties) { Classes = properties; } diff --git a/Source/FileManager/NamingTemplate/PropertyTagClass[TClass].cs b/Source/FileManager/NamingTemplate/PropertyTagClass[TClass].cs index beb335c8..56955cff 100644 --- a/Source/FileManager/NamingTemplate/PropertyTagClass[TClass].cs +++ b/Source/FileManager/NamingTemplate/PropertyTagClass[TClass].cs @@ -7,7 +7,7 @@ namespace FileManager.NamingTemplate; public delegate string PropertyFormatter(ITemplateTag templateTag, T value, string formatString); -public class PropertyTagClass : TagClass +public class PropertyTagClass : TagCollection { public PropertyTagClass(bool caseSensative = true) : base(typeof(TClass), caseSensative) { } diff --git a/Source/FileManager/NamingTemplate/TagClass.cs b/Source/FileManager/NamingTemplate/TagCollection.cs similarity index 93% rename from Source/FileManager/NamingTemplate/TagClass.cs rename to Source/FileManager/NamingTemplate/TagCollection.cs index 89967fdb..827db16e 100644 --- a/Source/FileManager/NamingTemplate/TagClass.cs +++ b/Source/FileManager/NamingTemplate/TagCollection.cs @@ -8,17 +8,17 @@ using System.Text.RegularExpressions; namespace FileManager.NamingTemplate; /// A collection of s registered to a single . -public abstract class TagClass : IEnumerable +public abstract class TagCollection : IEnumerable { - /// The of the 's TClass type. + /// The of the 's TClass type. public ParameterExpression Parameter { get; } - /// The s registered with this + /// The s registered with this public IEnumerator GetEnumerator() => PropertyTags.Select(p => p.TemplateTag).GetEnumerator(); protected RegexOptions Options { get; } = RegexOptions.Compiled; private List 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; diff --git a/Source/LibationFileManager/Templates.cs b/Source/LibationFileManager/Templates.cs index df50737c..bd9ef37e 100644 --- a/Source/LibationFileManager/Templates.cs +++ b/Source/LibationFileManager/Templates.cs @@ -225,19 +225,19 @@ namespace LibationFileManager }, new PropertyTagClass() { - { 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 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 diff --git a/Source/_Tests/FileManager.Tests/FileNamingTemplateTests.cs b/Source/_Tests/FileManager.Tests/FileNamingTemplateTests.cs index fc6529b5..bbe4863d 100644 --- a/Source/_Tests/FileManager.Tests/FileNamingTemplateTests.cs +++ b/Source/_Tests/FileManager.Tests/FileNamingTemplateTests.cs @@ -116,7 +116,7 @@ namespace NamingTemplateTests [DataRow("<-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("<-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);