diff --git a/Source/FileManager/NamingTemplate/ConditionalTagClass[TClass].cs b/Source/FileManager/NamingTemplate/ConditionalTagClass[TClass].cs index 69d3fdc9..da48b30f 100644 --- a/Source/FileManager/NamingTemplate/ConditionalTagClass[TClass].cs +++ b/Source/FileManager/NamingTemplate/ConditionalTagClass[TClass].cs @@ -24,13 +24,17 @@ public class ConditionalTagClass : TagClass { public ConditionalTagClass(bool caseSensative = true) :base(typeof(TClass), caseSensative) { } - public void RegisterCondition(ITemplateTag templateTag, Func propertyGetter) + /// + /// Register a conditional tag. + /// + /// A Func to get the condition's value from + public void Add(ITemplateTag templateTag, Func propertyGetter) { var expr = Expression.Call(Expression.Constant(propertyGetter.Target), propertyGetter.Method, Parameter); AddPropertyTag(new ConditionalTag(templateTag, Options, expr)); } - + private class ConditionalTag : TagBase, IClosingPropertyTag { public Regex NameCloseMatcher { get; } @@ -51,12 +55,10 @@ public class ConditionalTagClass : TagClass propertyTag = this; return true; } - else - { - exactName = null; - propertyTag = null; - return false; - } + + exactName = null; + propertyTag = null; + return false; } protected override Expression GetTagExpression(string exactName, string formatter) => formatter == "!" ? Expression.Not(ExpressionValue) : ExpressionValue; diff --git a/Source/FileManager/NamingTemplate/NamingTemplate.cs b/Source/FileManager/NamingTemplate/NamingTemplate.cs index 17ee7ec3..a3884123 100644 --- a/Source/FileManager/NamingTemplate/NamingTemplate.cs +++ b/Source/FileManager/NamingTemplate/NamingTemplate.cs @@ -9,7 +9,7 @@ public class NamingTemplate { public string TemplateText { get; private set; } public IEnumerable TagsInUse => _tagsInUse; - public IEnumerable TagsRegistered => Classes.SelectMany(p => p.TemplateTags).DistinctBy(f => f.TagName); + public IEnumerable TagsRegistered => Classes.SelectMany(t => t).DistinctBy(t => t.TagName); public IEnumerable Warnings => errors.Concat(warnings); public IEnumerable Errors => errors; @@ -183,6 +183,7 @@ public class NamingTemplate if (pc.StartsWith(template, out exactName, out propertyTag, out valueExpression)) return true; } + exactName = null; valueExpression = null; propertyTag = null; @@ -196,6 +197,7 @@ public class NamingTemplate if (pc.StartsWithClosing(template, out exactName, out closingPropertyTag)) return true; } + exactName = null; closingPropertyTag = null; return false; diff --git a/Source/FileManager/NamingTemplate/PropertyTagClass[TClass].cs b/Source/FileManager/NamingTemplate/PropertyTagClass[TClass].cs index 04eac040..beb335c8 100644 --- a/Source/FileManager/NamingTemplate/PropertyTagClass[TClass].cs +++ b/Source/FileManager/NamingTemplate/PropertyTagClass[TClass].cs @@ -17,9 +17,9 @@ public class PropertyTagClass : TagClass /// Type of the property from /// A Func to get the property value from /// Optional formatting function that accepts the property and a formatting string and returnes the value formatted to string - public void RegisterProperty(ITemplateTag templateTag, Func propertyGetter, PropertyFormatter formatter = null) + public void Add(ITemplateTag templateTag, Func propertyGetter, PropertyFormatter formatter = null) where U : struct - => RegisterPropertyInternal(templateTag, propertyGetter, formatter); + => RegisterProperty(templateTag, propertyGetter, formatter); /// /// Register a non-nullable value type property @@ -27,19 +27,19 @@ public class PropertyTagClass : TagClass /// Type of the property from /// A Func to get the property value from /// Optional formatting function that accepts the property and a formatting string and returnes the value formatted to string - public void RegisterProperty(ITemplateTag templateTag, Func propertyGetter, PropertyFormatter formatter = null) + public void Add(ITemplateTag templateTag, Func propertyGetter, PropertyFormatter formatter = null) where U : struct - => RegisterPropertyInternal(templateTag, propertyGetter, formatter); + => RegisterProperty(templateTag, propertyGetter, formatter); /// /// Register a string type property. /// /// A Func to get the string property from /// Optional formatting function that accepts the string property and a formatting string and returnes the value formatted to string - public void RegisterProperty(ITemplateTag templateTag, Func propertyGetter, PropertyFormatter formatter = null) - => RegisterPropertyInternal(templateTag, propertyGetter, formatter); + public void Add(ITemplateTag templateTag, Func propertyGetter, PropertyFormatter formatter = null) + => RegisterProperty(templateTag, propertyGetter, formatter); - private void RegisterPropertyInternal(ITemplateTag templateTag, Delegate propertyGetter, Delegate formatter) + private void RegisterProperty(ITemplateTag templateTag, Delegate propertyGetter, Delegate formatter) { if (formatter?.Target is not null) throw new ArgumentException($"{nameof(formatter)} must be a static method"); diff --git a/Source/FileManager/NamingTemplate/TagBase.cs b/Source/FileManager/NamingTemplate/TagBase.cs index 00622cac..613d2a53 100644 --- a/Source/FileManager/NamingTemplate/TagBase.cs +++ b/Source/FileManager/NamingTemplate/TagBase.cs @@ -13,7 +13,7 @@ internal interface IPropertyTag Type ReturnType { get; } /// The used to match in template strings. - public Regex NameMatcher { get; } + Regex NameMatcher { get; } /// /// Determine if the template string starts with , and if it does parse the tag to an @@ -52,12 +52,10 @@ internal abstract class TagBase : IPropertyTag propertyValue = GetTagExpression(exactName, match.Groups.Count == 2 ? match.Groups[1].Value.Trim() : ""); return true; } - else - { - exactName = null; - propertyValue = null; - return false; - } + + exactName = null; + propertyValue = null; + return false; } public override string ToString() diff --git a/Source/FileManager/NamingTemplate/TagClass.cs b/Source/FileManager/NamingTemplate/TagClass.cs index 1f044601..89967fdb 100644 --- a/Source/FileManager/NamingTemplate/TagClass.cs +++ b/Source/FileManager/NamingTemplate/TagClass.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; @@ -6,17 +7,16 @@ using System.Text.RegularExpressions; namespace FileManager.NamingTemplate; - /// A collection of s registered to a single . -public abstract class TagClass +public abstract class TagClass : IEnumerable { /// The of the 's TClass type. public ParameterExpression Parameter { get; } /// The s registered with this - public IEnumerable TemplateTags => PropertyTags.Select(p => p.TemplateTag); + public IEnumerator GetEnumerator() => PropertyTags.Select(p => p.TemplateTag).GetEnumerator(); protected RegexOptions Options { get; } = RegexOptions.Compiled; - private protected List PropertyTags { get; } = new(); + private List PropertyTags { get; } = new(); protected TagClass(Type classType, bool caseSensative = true) { @@ -42,6 +42,7 @@ public abstract class TagClass return true; } } + propertyValue = null; propertyTag = null; exactName = null; @@ -74,4 +75,6 @@ public abstract class TagClass if (!PropertyTags.Any(c => c.TemplateTag.TagName == propertyTag.TemplateTag.TagName)) PropertyTags.Add(propertyTag); } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } diff --git a/Source/FileManager/NamingTemplate/TemplatePart.cs b/Source/FileManager/NamingTemplate/TemplatePart.cs index b26e8887..1b7f7630 100644 --- a/Source/FileManager/NamingTemplate/TemplatePart.cs +++ b/Source/FileManager/NamingTemplate/TemplatePart.cs @@ -18,7 +18,7 @@ public class TemplatePart : IEnumerable public ITemplateTag TemplateTag { get; } /// The evaluated string. - public string Value { get; set; } + public string Value { get; } private TemplatePart previous; private TemplatePart next; diff --git a/Source/LibationFileManager/Templates.cs b/Source/LibationFileManager/Templates.cs index e62a62b2..df50737c 100644 --- a/Source/LibationFileManager/Templates.cs +++ b/Source/LibationFileManager/Templates.cs @@ -6,7 +6,6 @@ using AaxDecrypter; using Dinah.Core; using FileManager; using FileManager.NamingTemplate; -using Serilog.Formatting; namespace LibationFileManager { @@ -21,7 +20,7 @@ namespace LibationFileManager public const string ERROR_FULL_PATH_IS_INVALID = @"No colons or full paths allowed. Eg: should not start with C:\"; public const string WARNING_NO_CHAPTER_NUMBER_TAG = "Should include chapter number tag in template used for naming files which are split by chapter. Ie: or "; - //Assign the properties in the static constructor will require all + //Assigning the properties in the static constructor will require all //Templates users to have a valid configuration file. To allow tests //to work without access to Configuration, only load templates on demand. private static FolderTemplate _folder; @@ -35,6 +34,7 @@ namespace LibationFileManager public static ChapterTitleTemplate ChapterTitle => _chapterTitle ??= GetTemplate(Configuration.Instance.ChapterTitleTemplate); #region Template Parsing + public static T GetTemplate(string templateText) where T : Templates, ITemplate, new() => TryGetTemplate(templateText, out var template) ? template : GetDefaultTemplate(); @@ -53,23 +53,25 @@ namespace LibationFileManager { Configuration.Instance.PropertyChanged += [PropertyChangeFilter(nameof(Configuration.FolderTemplate))] - (_,e) => _folder = GetTemplate((string)e.NewValue); + (_,e) => _folder = GetTemplate((string)e.NewValue); - Configuration.Instance.PropertyChanged - += [PropertyChangeFilter(nameof(Configuration.FileTemplate))] - (_, e) => _file = GetTemplate((string)e.NewValue); + Configuration.Instance.PropertyChanged += + [PropertyChangeFilter(nameof(Configuration.FileTemplate))] + (_, e) => _file = GetTemplate((string)e.NewValue); - Configuration.Instance.PropertyChanged - += [PropertyChangeFilter(nameof(Configuration.ChapterFileTemplate))] - (_, e) => _chapterFile = GetTemplate((string)e.NewValue); + Configuration.Instance.PropertyChanged += + [PropertyChangeFilter(nameof(Configuration.ChapterFileTemplate))] + (_, e) => _chapterFile = GetTemplate((string)e.NewValue); - Configuration.Instance.PropertyChanged - += [PropertyChangeFilter(nameof(Configuration.ChapterTitleTemplate))] - (_, e) => _chapterTitle = GetTemplate((string)e.NewValue); + Configuration.Instance.PropertyChanged += + [PropertyChangeFilter(nameof(Configuration.ChapterTitleTemplate))] + (_, e) => _chapterTitle = GetTemplate((string)e.NewValue); } + #endregion #region Template Properties + public IEnumerable TagsRegistered => Template.TagsRegistered.Cast(); public IEnumerable TagsInUse => Template.TagsInUse.Cast(); public abstract string Name { get; } @@ -77,7 +79,6 @@ namespace LibationFileManager public string TemplateText => Template.TemplateText; protected NamingTemplate Template { get; private set; } - #endregion #region validation @@ -152,7 +153,7 @@ namespace LibationFileManager part.Insert(maxIndex, maxEntry.Remove(maxLength - 1, 1)); } } - //Any + var fullPath = Path.Combine(pathParts.Select(fileParts => string.Join("", fileParts)).Prepend(baseDir).ToArray()); return FileUtility.GetValidFilename(fullPath, replacements, fileExtension, returnFirstExisting); @@ -163,7 +164,7 @@ namespace LibationFileManager /// returned as empty directories and are taken care of by Path.Combine() /// /// A List of template directories. Each directory is a list of template part strings - private List> GetPathParts(IEnumerable templateParts) + private static List> GetPathParts(IEnumerable templateParts) { List> directories = new(); List dir = new(); @@ -190,64 +191,54 @@ namespace LibationFileManager #region Registered Template Properties - private static readonly PropertyTagClass filePropertyTags = GetFilePropertyTags(); - private static readonly ConditionalTagClass conditionalTags = GetConditionalTags(); - private static readonly List chapterPropertyTags = GetChapterPropertyTags(); - - private static ConditionalTagClass GetConditionalTags() + private static readonly PropertyTagClass filePropertyTags = new() { - ConditionalTagClass lbConditions = new(); + { TemplateTags.Id, lb => lb.AudibleProductId }, + { TemplateTags.Title, lb => lb.Title, StringFormatter }, + { TemplateTags.TitleShort, lb => lb.Title.IndexOf(':') < 1 ? lb.Title : lb.Title.Substring(0, lb.Title.IndexOf(':')), StringFormatter }, + { TemplateTags.Author, lb => lb.AuthorNames, StringFormatter }, + { TemplateTags.FirstAuthor, lb => lb.FirstAuthor, StringFormatter }, + { TemplateTags.Narrator, lb => lb.NarratorNames, StringFormatter }, + { TemplateTags.FirstNarrator, lb => lb.FirstNarrator, StringFormatter }, + { TemplateTags.Series, lb => lb.SeriesName, StringFormatter }, + { TemplateTags.SeriesNumber, lb => lb.SeriesNumber, IntegerFormatter }, + { TemplateTags.Language, lb => lb.Language, StringFormatter }, + { TemplateTags.LanguageShort, lb => getLanguageShort(lb.Language), StringFormatter }, + { TemplateTags.Bitrate, lb => lb.BitRate, IntegerFormatter }, + { TemplateTags.SampleRate, lb => lb.SampleRate, IntegerFormatter }, + { TemplateTags.Channels, lb => lb.Channels, IntegerFormatter }, + { TemplateTags.Account, lb => lb.Account, StringFormatter }, + { TemplateTags.Locale, lb => lb.Locale, StringFormatter }, + { TemplateTags.YearPublished, lb => lb.YearPublished, IntegerFormatter }, + { TemplateTags.DatePublished, lb => lb.DatePublished, DateTimeFormatter }, + { TemplateTags.DateAdded, lb => lb.DateAdded, DateTimeFormatter }, + { TemplateTags.FileDate, lb => lb.FileDate, DateTimeFormatter }, + }; - lbConditions.RegisterCondition(TemplateTags.IfSeries, lb => lb.IsSeries); - lbConditions.RegisterCondition(TemplateTags.IfPodcast, lb => lb.IsPodcast); - lbConditions.RegisterCondition(TemplateTags.IfBookseries, lb => lb.IsSeries && !lb.IsPodcast); - - return lbConditions; - } - - private static PropertyTagClass GetFilePropertyTags() + private static readonly List chapterPropertyTags = new() { - PropertyTagClass lbProperties = new(); - lbProperties.RegisterProperty(TemplateTags.Id, lb => lb.AudibleProductId); - lbProperties.RegisterProperty(TemplateTags.Title, lb => lb.Title, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.TitleShort, lb => lb.Title.IndexOf(':') < 1 ? lb.Title : lb.Title.Substring(0, lb.Title.IndexOf(':')), StringFormatter); - lbProperties.RegisterProperty(TemplateTags.Author, lb => lb.AuthorNames, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.FirstAuthor, lb => lb.FirstAuthor, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.Narrator, lb => lb.NarratorNames, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.FirstNarrator, lb => lb.FirstNarrator, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.Series, lb => lb.SeriesName, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.SeriesNumber, lb => lb.SeriesNumber, IntegerFormatter); - lbProperties.RegisterProperty(TemplateTags.Language, lb => lb.Language, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.LanguageShort, lb => getLanguageShort(lb.Language), StringFormatter); - lbProperties.RegisterProperty(TemplateTags.Bitrate, lb => lb.BitRate, IntegerFormatter); - lbProperties.RegisterProperty(TemplateTags.SampleRate, lb => lb.SampleRate, IntegerFormatter); - lbProperties.RegisterProperty(TemplateTags.Channels, lb => lb.Channels, IntegerFormatter); - lbProperties.RegisterProperty(TemplateTags.Account, lb => lb.Account, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.Locale, lb => lb.Locale, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.YearPublished, lb => lb.YearPublished, IntegerFormatter); - lbProperties.RegisterProperty(TemplateTags.DatePublished, lb => lb.DatePublished, DateTimeFormatter); - lbProperties.RegisterProperty(TemplateTags.DateAdded, lb => lb.DateAdded, DateTimeFormatter); - lbProperties.RegisterProperty(TemplateTags.FileDate, lb => lb.FileDate, DateTimeFormatter); - return lbProperties; - } + new PropertyTagClass() + { + { TemplateTags.Title, lb => lb.Title, StringFormatter }, + { TemplateTags.TitleShort, lb => lb?.Title?.IndexOf(':') > 0 ? lb.Title.Substring(0, lb.Title.IndexOf(':')) : lb.Title, StringFormatter }, + { TemplateTags.Series, lb => lb.SeriesName, StringFormatter }, + }, + new PropertyTagClass() + { + { TemplateTags.ChCount, lb => lb.PartsTotal, IntegerFormatter }, + { TemplateTags.ChNumber, lb => lb.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 } + } + }; - private static List GetChapterPropertyTags() + private static readonly ConditionalTagClass conditionalTags = new() { - PropertyTagClass lbProperties = new(); - PropertyTagClass multiConvertProperties = new(); - - lbProperties.RegisterProperty(TemplateTags.Title, lb => lb.Title, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.TitleShort, lb => lb?.Title?.IndexOf(':') > 0 ? lb.Title.Substring(0, lb.Title.IndexOf(':')) : lb.Title, StringFormatter); - lbProperties.RegisterProperty(TemplateTags.Series, lb => lb.SeriesName, StringFormatter); - - multiConvertProperties.RegisterProperty(TemplateTags.ChCount, lb => lb.PartsTotal, IntegerFormatter); - multiConvertProperties.RegisterProperty(TemplateTags.ChNumber, lb => lb.PartsPosition, IntegerFormatter); - multiConvertProperties.RegisterProperty(TemplateTags.ChNumber0, m => m.PartsPosition.ToString("D" + ((int)Math.Log10(m.PartsTotal) + 1))); - multiConvertProperties.RegisterProperty(TemplateTags.ChTitle, m => m.Title, StringFormatter); - multiConvertProperties.RegisterProperty(TemplateTags.FileDate, lb => lb.FileDate, DateTimeFormatter); - - return new List { lbProperties, multiConvertProperties }; - } + {TemplateTags.IfSeries, lb => lb.IsSeries }, + {TemplateTags.IfPodcast, lb => lb.IsPodcast }, + {TemplateTags.IfBookseries, lb => lb.IsSeries && !lb.IsPodcast }, + }; #endregion @@ -298,17 +289,12 @@ namespace LibationFileManager => TemplateText?.Length >= 2 && Path.IsPathFullyQualified(TemplateText) ? base.Errors.Append(ERROR_FULL_PATH_IS_INVALID) : base.Errors; protected override List GetTemplatePartsStrings(List parts, ReplacementCharacters replacements) - { - foreach (var tp in parts) - { + => parts + .Select(tp => tp.TemplateTag is null //FolderTemplate literals can have directory separator characters - if (tp.TemplateTag is null) - tp.Value = replacements.ReplacePathChars(tp.Value.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)); - else - tp.Value = replacements.ReplaceFilenameChars(tp.Value); - } - return parts.Select(p => p.Value).ToList(); - } + ? replacements.ReplacePathChars(tp.Value.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)) + : replacements.ReplaceFilenameChars(tp.Value) + ).ToList(); } public class FileTemplate : Templates, ITemplate @@ -324,8 +310,7 @@ namespace LibationFileManager public override string Name => "Chapter File Template"; public override string Description => Configuration.GetDescription(nameof(Configuration.ChapterFileTemplate)); public static string DefaultTemplate { get; } = " [<id>] - <ch# 0> - <ch title>"; - public static IEnumerable<TagClass> TagClass { get; } - = chapterPropertyTags.Append(filePropertyTags).Append(conditionalTags); + public static IEnumerable<TagClass> TagClass { get; } = chapterPropertyTags.Append(filePropertyTags).Append(conditionalTags); public override IEnumerable<string> Warnings => Template.TagsInUse.Any(t => t.TagName.In(TemplateTags.ChNumber.TagName, TemplateTags.ChNumber0.TagName)) @@ -338,8 +323,7 @@ namespace LibationFileManager public override string Name => "Chapter Title Template"; public override string Description => Configuration.GetDescription(nameof(Configuration.ChapterTitleTemplate)); public static string DefaultTemplate => "<ch#> - <title short>: <ch title>"; - public static IEnumerable<TagClass> TagClass { get; } - = chapterPropertyTags.Append(conditionalTags); + public static IEnumerable<TagClass> TagClass { get; } = chapterPropertyTags.Append(conditionalTags); protected override IEnumerable<string> GetTemplatePartsStrings(List<TemplatePart> parts, ReplacementCharacters replacements) => parts.Select(p => p.Value); diff --git a/Source/_Tests/FileManager.Tests/FileNamingTemplateTests.cs b/Source/_Tests/FileManager.Tests/FileNamingTemplateTests.cs index 90a04e15..fc6529b5 100644 --- a/Source/_Tests/FileManager.Tests/FileNamingTemplateTests.cs +++ b/Source/_Tests/FileManager.Tests/FileNamingTemplateTests.cs @@ -41,12 +41,39 @@ namespace NamingTemplateTests [TestClass] public class GetPortionFilename { - PropertyTagClass<PropertyClass1> props1 = new(); - PropertyTagClass<PropertyClass2> props2 = new(); - PropertyTagClass<PropertyClass3> props3 = new(); - ConditionalTagClass<PropertyClass1> conditional1 = new(); - ConditionalTagClass<PropertyClass2> conditional2 = new(); - ConditionalTagClass<PropertyClass3> conditional3 = new(); + PropertyTagClass<PropertyClass1> props1 = new() + { + { new TemplateTag { TagName = "item1" }, i => i.Item1 }, + { new TemplateTag { TagName = "item2" }, i => i.Item2 }, + { new TemplateTag { TagName = "item3" }, i => i.Item3 } + }; + + PropertyTagClass<PropertyClass2> props2 = new() + { + { new TemplateTag { TagName = "item1" }, i => i.Item1 }, + { new TemplateTag { TagName = "item2" }, i => i.Item2 }, + { new TemplateTag { TagName = "item3" }, i => i.Item3 }, + { new TemplateTag { TagName = "item4" }, i => i.Item4 }, + }; + PropertyTagClass<PropertyClass3> props3 = new() + { + { new TemplateTag { TagName = "item3_1" }, i => i.Item1 }, + { new TemplateTag { TagName = "item3_2" }, i => i.Item2 }, + { new TemplateTag { TagName = "item3_3" }, i => i.Item3 }, + { new TemplateTag { TagName = "item3_4" }, i => i.Item4 }, + }; + ConditionalTagClass<PropertyClass1> conditional1 = new() + { + { new TemplateTag { TagName = "ifc1" }, i => i.Condition }, + }; + ConditionalTagClass<PropertyClass2> conditional2 = new() + { + { new TemplateTag { TagName = "ifc2" }, i => i.Condition }, + }; + ConditionalTagClass<PropertyClass3> conditional3 = new() + { + { new TemplateTag { TagName = "ifc3" }, i => i.Condition }, + }; PropertyClass1 propertyClass1 = new() { @@ -74,27 +101,6 @@ namespace NamingTemplateTests Condition = true }; - public GetPortionFilename() - { - props1.RegisterProperty(new TemplateTag { TagName = "item1" }, i => i.Item1); - props1.RegisterProperty(new TemplateTag { TagName = "item2" }, i => i.Item2); - props1.RegisterProperty(new TemplateTag { TagName = "item3" }, i => i.Item3); - - props2.RegisterProperty(new TemplateTag { TagName = "item1" }, i => i.Item1); - props2.RegisterProperty(new TemplateTag { TagName = "item2" }, i => i.Item2); - props2.RegisterProperty(new TemplateTag { TagName = "item3" }, i => i.Item3); - props2.RegisterProperty(new TemplateTag { TagName = "item4" }, i => i.Item4); - - props3.RegisterProperty(new TemplateTag { TagName = "item3_1" }, i => i.Item1); - props3.RegisterProperty(new TemplateTag { TagName = "item3_2" }, i => i.Item2); - props3.RegisterProperty(new TemplateTag { TagName = "item3_3" }, i => i.Item3); - props3.RegisterProperty(new TemplateTag { TagName = "item3_4" }, i => i.Item4); - - conditional1.RegisterCondition(new TemplateTag { TagName = "ifc1" }, i => i.Condition); - conditional2.RegisterCondition(new TemplateTag { TagName = "ifc2" }, i => i.Condition); - conditional3.RegisterCondition(new TemplateTag { TagName = "ifc3" }, i => i.Condition); - } - [TestMethod] [DataRow("<item1>", "prop1_item1", 1)] @@ -154,10 +160,10 @@ namespace NamingTemplateTests [DataRow("<item2_2_null[l]>", "")] public void formatting(string inStr, string outStr) { - props1.RegisterProperty(new TemplateTag { TagName = "int1" }, i => i.Int1, formatInt); - props3.RegisterProperty(new TemplateTag { TagName = "int2" }, i => i.Int2, formatInt); - props3.RegisterProperty(new TemplateTag { TagName = "item3_format" }, i => i.Item3, formatString); - props2.RegisterProperty(new TemplateTag { TagName = "item2_2_null" }, i => i.Item2, formatString); + props1.Add(new TemplateTag { TagName = "int1" }, i => i.Int1, formatInt); + props3.Add(new TemplateTag { TagName = "int2" }, i => i.Int2, formatInt); + 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 });