diff --git a/src/Simplify.Templates.Tests/Model/TemplateModelExtensionsTests.cs b/src/Simplify.Templates.Tests/Model/TemplateModelExtensionsTests.cs index c6dc2411..dbacafc7 100644 --- a/src/Simplify.Templates.Tests/Model/TemplateModelExtensionsTests.cs +++ b/src/Simplify.Templates.Tests/Model/TemplateModelExtensionsTests.cs @@ -22,33 +22,33 @@ public void Initialize() public void Set_NullModel_ReplacesWithNothing() { // Act - _template.Model(null).Set(); + _template.Model(null!).Set(); // Assert - Assert.AreEqual(" ", _template.Get()); + Assert.That(_template.Get(), Is.EqualTo(" ")); } [Test] public void Set_NullModelWithWith_ReplacesWithNothing() { // Act - _template.Model(null).With(x => x.CreationTime, x => x.ToString("dd.MM.yyyy")).Set(); + _template.Model(null!).With(x => x.CreationTime, x => x.ToString("dd.MM.yyyy")).Set(); // Assert - Assert.AreEqual(" ", _template.Get()); + Assert.That(_template.Get(), Is.EqualTo(" ")); } [Test] public void Set_Model_SetCorrectly() { // Arrange - var model = new TestModel { CreationTime = new DateTime(2014, 10, 5), Name = "Foo", EMail = "Foo@example.com", ID = 5 }; + var model = new TestModel { CreationTime = new DateTime(2014, 10, 5, 0, 0, 0, DateTimeKind.Local), Name = "Foo", EMail = "Foo@example.com", ID = 5 }; // Act _template.Model(model).With(x => x.CreationTime, x => x.ToString("dd.MM.yyyy")).Set(); // Assert - Assert.AreEqual("5 Foo Foo@example.com 05.10.2014", _template.Get()); + Assert.That(_template.Get(), Is.EqualTo("5 Foo Foo@example.com 05.10.2014")); } [Test] @@ -66,7 +66,7 @@ public void Set_EverythingIsNull_SetCorrectly() _template.Model(model).Set(); // Assert - Assert.AreEqual(" ", _template.Get()); + Assert.That(_template.Get(), Is.EqualTo(" ")); } [Test] @@ -87,7 +87,7 @@ public void Add_TwoModels_DataCombined() _template.Model(model2).Add(); // Assert - Assert.AreEqual("TestFoo test@test.comfoomail@test.com", _template.Get()); + Assert.That(_template.Get(), Is.EqualTo("TestFoo test@test.comfoomail@test.com")); } [Test] @@ -105,7 +105,7 @@ public void Set_ModelWithBaseClass_BaseClassFieldsAlsoSet() _template.Model(model).Set(); // Assert - Assert.AreEqual("3 Hello!", _template.Get()); + Assert.That(_template.Get(), Is.EqualTo("3 Hello!")); } [Test] @@ -123,6 +123,6 @@ public void Set_ModelWithPrefix_PrefixAdded() _template.Model(model, "Model").Set(); // Assert - Assert.AreEqual("3", _template.Get()); + Assert.That(_template.Get(), Is.EqualTo("3")); } } \ No newline at end of file diff --git a/src/Simplify.Templates.Tests/Simplify.Templates.Tests.csproj b/src/Simplify.Templates.Tests/Simplify.Templates.Tests.csproj index c47bcc21..e80ac984 100644 --- a/src/Simplify.Templates.Tests/Simplify.Templates.Tests.csproj +++ b/src/Simplify.Templates.Tests/Simplify.Templates.Tests.csproj @@ -1,6 +1,7 @@  - net6.0 + net6.0;net48 + latest Alexander Krylkov Simplify @@ -8,20 +9,27 @@ Licensed under LGPL - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + PreserveNewest + Never @@ -45,6 +53,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/Simplify.Templates.Tests/TemplateAddExtensionsTests.cs b/src/Simplify.Templates.Tests/TemplateAddExtensionsTests.cs index 8d724cf9..0ba07ff0 100644 --- a/src/Simplify.Templates.Tests/TemplateAddExtensionsTests.cs +++ b/src/Simplify.Templates.Tests/TemplateAddExtensionsTests.cs @@ -21,10 +21,10 @@ public void Initialize() public void Set_NullTemplate_Empty() { // Act - _tpl.Add(VariableName, (ITemplate)null); + _tpl.Add(VariableName, ((ITemplate)null)!); // Assert - Assert.AreEqual("", _tpl.Get()); + Assert.That(_tpl.Get(), Is.Empty); } [Test] @@ -34,7 +34,7 @@ public void Set_Template_SetCorrectly() _tpl.Add(VariableName, TemplateBuilder.FromString("a").Build()); // Assert - Assert.AreEqual("a", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("a")); } [Test] @@ -44,7 +44,7 @@ public void Set_NullObject_Empty() _tpl.Add(VariableName, (object)null); // Assert - Assert.AreEqual("", _tpl.Get()); + Assert.That(_tpl.Get(), Is.Empty); } [Test] @@ -54,7 +54,7 @@ public void Set_Object_ObjectClassName() _tpl.Add(VariableName, new object()); // Assert - Assert.AreEqual("System.Object", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("System.Object")); } [Test] @@ -64,7 +64,7 @@ public void Set_Int_SetCorrectly() _tpl.Add(VariableName, 17); // Assert - Assert.AreEqual("17", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("17")); } [Test] @@ -76,7 +76,7 @@ public void Set_MultipleInt_AllSetCorrectly() _tpl.Add(VariableName, 63); // Assert - Assert.AreEqual("1763", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("1763")); } [Test] @@ -86,7 +86,7 @@ public void Set_Long_SetCorrectly() _tpl.Add(VariableName, (long)16); // Assert - Assert.AreEqual("16", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("16")); } [Test] @@ -96,16 +96,16 @@ public void Set_Decimal_SetCorrectly() _tpl.Add(VariableName, 15.5m); // Assert - Assert.AreEqual("15.5", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("15.5")); } [Test] public void Set_Double_SetCorrectly() { // Act - _tpl.Add(VariableName, 1123456789123.123); + _tpl.Add(VariableName, 1123456789123.12); // Assert - Assert.AreEqual("1123456789123.123", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("1123456789123.12")); } } \ No newline at end of file diff --git a/src/Simplify.Templates.Tests/TemplateBuilderFileNotFoundTests.cs b/src/Simplify.Templates.Tests/TemplateBuilderFileNotFoundTests.cs index 5dcf9b4e..e07da0f6 100644 --- a/src/Simplify.Templates.Tests/TemplateBuilderFileNotFoundTests.cs +++ b/src/Simplify.Templates.Tests/TemplateBuilderFileNotFoundTests.cs @@ -9,15 +9,15 @@ public class TemplateBuilderFileNotFoundTests { private const string FilePath = "NotFoundFile.txt"; - private static readonly object[] _testCases = - { + private static readonly object[] TestCases = + [ (TestDelegate) (() => TemplateBuilder.FromFile(FilePath)), (TestDelegate) (() => TemplateBuilder.FromLocalFile(FilePath)), (TestDelegate) (() => TemplateBuilder.FromAssembly(FilePath, Assembly.GetExecutingAssembly())), (TestDelegate) (() => TemplateBuilder.FromCurrentAssembly(FilePath)) - }; + ]; - [TestCaseSource(nameof(_testCases))] + [TestCaseSource(nameof(TestCases))] public void FileNotExist_FileNotFoundException(TestDelegate templateBuilder) { // Act diff --git a/src/Simplify.Templates.Tests/TemplateBuilderFromStringTests.cs b/src/Simplify.Templates.Tests/TemplateBuilderFromStringTests.cs index c1c73d48..edf259a0 100644 --- a/src/Simplify.Templates.Tests/TemplateBuilderFromStringTests.cs +++ b/src/Simplify.Templates.Tests/TemplateBuilderFromStringTests.cs @@ -11,10 +11,10 @@ public class TemplateBuilderFromStringTests public void FromString_NullString_TemplateGetEqual() { // Act - var ex = Assert.Throws(() => TemplateBuilder.FromString(null)); + var ex = Assert.Throws(() => TemplateBuilder.FromString(null!)); // Assert - Assert.AreEqual("Value cannot be null. (Parameter 'text')", ex.Message); + Assert.That(ex!.Message, Does.Contain("Value cannot be null")); } [Test] @@ -26,7 +26,7 @@ public void Build_FromString_TemplateContentIsCorrect() .Build(); // Assert - Assert.AreEqual("test", tpl.Get()); + Assert.That(tpl.Get(), Is.EqualTo("test")); } [Test] @@ -38,7 +38,7 @@ public async Task BuildAsync_FromString_TemplateContentIsCorrect() .BuildAsync(); // Assert - Assert.AreEqual("test", tpl.Get()); + Assert.That(tpl.Get(), Is.EqualTo("test")); } [Test] @@ -51,6 +51,6 @@ public void FromStringFixLineEndingsHtml_WithLineBreak_LineEndingReplacedWithBrs .Build(); // Assert - Assert.AreEqual("test
test2", tpl.Get()); + Assert.That(tpl.Get(), Is.EqualTo("test
test2")); } } \ No newline at end of file diff --git a/src/Simplify.Templates.Tests/TemplateBuilderLocalizationTests.cs b/src/Simplify.Templates.Tests/TemplateBuilderLocalizationTests.cs index 86add5bf..1f30a33e 100644 --- a/src/Simplify.Templates.Tests/TemplateBuilderLocalizationTests.cs +++ b/src/Simplify.Templates.Tests/TemplateBuilderLocalizationTests.cs @@ -12,15 +12,15 @@ public class TemplateBuilderLocalizationTests private const string LocalTestFilePath = "TestTemplates/Local/LocalizationTest.tpl"; private const string EmbeddedTestFilePath = "TestTemplates/Embedded/LocalizationTest.tpl"; - private static readonly object[] _testCases = - { + private static readonly object[] TestCases = + [ (TemplateBuilderDelegate) (() => TemplateBuilder.FromFile(FileUtil.ConstructFullFilePath(LocalTestFilePath))), (TemplateBuilderDelegate) (() => TemplateBuilder.FromLocalFile(LocalTestFilePath)), (TemplateBuilderDelegate) (() => TemplateBuilder.FromAssembly(EmbeddedTestFilePath, Assembly.GetExecutingAssembly())), (TemplateBuilderDelegate) (() => TemplateBuilder.FromCurrentAssembly(EmbeddedTestFilePath)) - }; + ]; - [TestCaseSource(nameof(_testCases))] + [TestCaseSource(nameof(TestCases))] public void Build_LocalizableDifferentFromBase_LocalizableLoadedWithBaseReplacements(TemplateBuilderDelegate templateBuilder) { // Arrange @@ -32,10 +32,10 @@ public void Build_LocalizableDifferentFromBase_LocalizableLoadedWithBaseReplacem .Build(); // Assert - Assert.AreEqual("текст1 text2", tpl.Get()); + Assert.That(tpl.Get(), Is.EqualTo("текст1 text2")); } - [TestCaseSource(nameof(_testCases))] + [TestCaseSource(nameof(TestCases))] public async Task BuildAsync_LocalizableDifferentFromBase_LocalizableLoadedWithBaseReplacements(TemplateBuilderDelegate templateBuilder) { // Arrange @@ -47,10 +47,10 @@ public async Task BuildAsync_LocalizableDifferentFromBase_LocalizableLoadedWithB .BuildAsync(); // Assert - Assert.AreEqual("текст1 text2", tpl.Get()); + Assert.That(tpl.Get(), Is.EqualTo("текст1 text2")); } - [TestCaseSource(nameof(_testCases))] + [TestCaseSource(nameof(TestCases))] public void Build_LocalizableFromCurrentThreadLanguageDifferentFromBase_LocalizableLoadedWithBaseReplacements( TemplateBuilderDelegate templateBuilder) { @@ -65,10 +65,10 @@ public void Build_LocalizableFromCurrentThreadLanguageDifferentFromBase_Localiza .Build(); // Assert - Assert.AreEqual("текст1 text2", tpl.Get()); + Assert.That(tpl.Get(), Is.EqualTo("текст1 text2")); } - [TestCaseSource(nameof(_testCases))] + [TestCaseSource(nameof(TestCases))] public async Task BuildAsync_LocalizableFromCurrentThreadLanguageDifferentFromBase_LocalizableLoadedWithBaseReplacements( TemplateBuilderDelegate templateBuilder) { @@ -83,6 +83,6 @@ public async Task BuildAsync_LocalizableFromCurrentThreadLanguageDifferentFromBa .BuildAsync(); // Assert - Assert.AreEqual("текст1 text2", tpl.Get()); + Assert.That(tpl.Get(), Is.EqualTo("текст1 text2")); } } \ No newline at end of file diff --git a/src/Simplify.Templates.Tests/TemplateBuilderNullTests.cs b/src/Simplify.Templates.Tests/TemplateBuilderNullTests.cs index db50cd43..a3f13597 100644 --- a/src/Simplify.Templates.Tests/TemplateBuilderNullTests.cs +++ b/src/Simplify.Templates.Tests/TemplateBuilderNullTests.cs @@ -7,21 +7,21 @@ namespace Simplify.Templates.Tests; [TestFixture] public class TemplateBuilderNullTests { - private static readonly object[] _testCases = - { - (TestDelegate) (() => TemplateBuilder.FromFile(null)), - (TestDelegate) (() => TemplateBuilder.FromLocalFile(null)), - (TestDelegate) (() => TemplateBuilder.FromAssembly(null, Assembly.GetExecutingAssembly())), - (TestDelegate) (() => TemplateBuilder.FromCurrentAssembly(null)) - }; + private static readonly object[] TestCases = + [ + (TestDelegate) (() => TemplateBuilder.FromFile(null!)), + (TestDelegate) (() => TemplateBuilder.FromLocalFile(null!)), + (TestDelegate) (() => TemplateBuilder.FromAssembly(null!, Assembly.GetExecutingAssembly())), + (TestDelegate) (() => TemplateBuilder.FromCurrentAssembly(null!)) + ]; - [TestCaseSource(nameof(_testCases))] + [TestCaseSource(nameof(TestCases))] public void NullPath_ArgumentNullException(TestDelegate templateBuilder) { // Act var ex = Assert.Throws(templateBuilder); // Assert - Assert.AreEqual("Value cannot be null or empty. (Parameter 'filePath')", ex.Message); + Assert.That(ex!.Message, Does.Contain("Value cannot be null or empty.")); } } \ No newline at end of file diff --git a/src/Simplify.Templates.Tests/TemplateBuilderSimpleContentTests.cs b/src/Simplify.Templates.Tests/TemplateBuilderSimpleContentTests.cs index aa89387a..75fd3b4b 100644 --- a/src/Simplify.Templates.Tests/TemplateBuilderSimpleContentTests.cs +++ b/src/Simplify.Templates.Tests/TemplateBuilderSimpleContentTests.cs @@ -10,15 +10,15 @@ public class TemplateBuilderSimpleContentTests private const string LocalTestFilePath = "TestTemplates/Local/TestFile.txt"; private const string EmbeddedTestFilePath = "TestTemplates/Embedded/TestFile.txt"; - private static readonly object[] _testCases = - { + private static readonly object[] TestCases = + [ (TemplateBuilderDelegate) (() => TemplateBuilder.FromFile(FileUtil.ConstructFullFilePath(LocalTestFilePath))), (TemplateBuilderDelegate) (() => TemplateBuilder.FromLocalFile(LocalTestFilePath)), (TemplateBuilderDelegate) (() => TemplateBuilder.FromAssembly(EmbeddedTestFilePath, Assembly.GetExecutingAssembly())), (TemplateBuilderDelegate) (() => TemplateBuilder.FromCurrentAssembly(EmbeddedTestFilePath)) - }; + ]; - [TestCaseSource(nameof(_testCases))] + [TestCaseSource(nameof(TestCases))] public void Build_TemplateContentIsCorrect(TemplateBuilderDelegate templateBuilder) { // Arrange @@ -28,10 +28,10 @@ public void Build_TemplateContentIsCorrect(TemplateBuilderDelegate templateBuild var tpl = builder.Build(); // Assert - Assert.AreEqual("test", tpl.Get()); + Assert.That(tpl.Get(), Is.LessThanOrEqualTo("test")); } - [TestCaseSource(nameof(_testCases))] + [TestCaseSource(nameof(TestCases))] public async Task BuildAsync_TemplateContentIsCorrect(TemplateBuilderDelegate templateBuilder) { // Arrange @@ -41,6 +41,30 @@ public async Task BuildAsync_TemplateContentIsCorrect(TemplateBuilderDelegate te var tpl = await builder.BuildAsync(); // Assert - Assert.AreEqual("test", tpl.Get()); + Assert.That(tpl.Get(), Is.LessThanOrEqualTo("test")); + } + + [Test] + public void Build_EmptyFile_EmptyString() + { + // Act + var tpl = TemplateBuilder + .FromLocalFile("TestTemplates/Local/EmptyFIle.txt") + .Build(); + + // Assert + Assert.That(tpl.Get(), Is.Empty); + } + + [Test] + public void Build_EmptyEmbeddedFile_EmptyString() + { + // Act + var tpl = TemplateBuilder + .FromLocalFile("TestTemplates/Embedded/EmptyFIle.txt") + .Build(); + + // Assert + Assert.That(tpl.Get(), Is.Empty); } } \ No newline at end of file diff --git a/src/Simplify.Templates.Tests/TemplateSetExtensionsTests.cs b/src/Simplify.Templates.Tests/TemplateSetExtensionsTests.cs index 52cdf4c8..b7b41692 100644 --- a/src/Simplify.Templates.Tests/TemplateSetExtensionsTests.cs +++ b/src/Simplify.Templates.Tests/TemplateSetExtensionsTests.cs @@ -21,10 +21,10 @@ public void Initialize() public void Set_NullTemplate_Empty() { // Act - _tpl.Set(VariableName, (ITemplate)null); + _tpl.Set(VariableName, ((ITemplate)null)!); // Assert - Assert.AreEqual("", _tpl.Get()); + Assert.That(_tpl.Get(), Is.Empty); } [Test] @@ -34,7 +34,7 @@ public void Set_Template_SetCorrectly() _tpl.Set(VariableName, TemplateBuilder.FromString("a").Build()); // Assert - Assert.AreEqual("a", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("a")); } [Test] @@ -44,7 +44,7 @@ public void Set_NullObject_Empty() _tpl.Set(VariableName, (object)null); // Assert - Assert.AreEqual("", _tpl.Get()); + Assert.That(_tpl.Get(), Is.Empty); } [Test] @@ -54,7 +54,7 @@ public void Set_Object_ObjectClassName() _tpl.Set(VariableName, new object()); // Assert - Assert.AreEqual("System.Object", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("System.Object")); } [Test] @@ -64,7 +64,7 @@ public void Set_Int_SetCorrectly() _tpl.Set(VariableName, 17); // Assert - Assert.AreEqual("17", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("17")); } [Test] @@ -74,7 +74,7 @@ public void Set_Long_SetCorrectly() _tpl.Set(VariableName, (long)16); // Assert - Assert.AreEqual("16", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("16")); } [Test] @@ -84,16 +84,16 @@ public void Set_Decimal_SetCorrectly() _tpl.Set(VariableName, 15.5m); // Assert - Assert.AreEqual("15.5", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("15.5")); } [Test] public void Set_Double_SetCorrectly() { // Act - _tpl.Set(VariableName, 1123456789123.123); + _tpl.Set(VariableName, 1123456789123.12); // Assert - Assert.AreEqual("1123456789123.123", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("1123456789123.12")); } } \ No newline at end of file diff --git a/src/Simplify.Templates.Tests/TemplateTests.cs b/src/Simplify.Templates.Tests/TemplateTests.cs index 0c96dec3..1f116882 100644 --- a/src/Simplify.Templates.Tests/TemplateTests.cs +++ b/src/Simplify.Templates.Tests/TemplateTests.cs @@ -22,30 +22,30 @@ public void Initialize() public void Build_FromNullString_ArgumentNullException() { // Act - var ex = Assert.Throws(() => TemplateBuilder.FromString(null)); + var ex = Assert.Throws(() => TemplateBuilder.FromString(null!)); // Assert - Assert.AreEqual("Value cannot be null. (Parameter 'text')", ex.Message); + Assert.That(ex!.Message, Does.Contain("Value cannot be null")); } [Test] public void Set_NullVariableName_ArgumentNullException() { // Act - var ex = Assert.Throws(() => _tpl.Set(null, "test")); + var ex = Assert.Throws(() => _tpl.Set(null!, "test")); // Assert - Assert.AreEqual("Value cannot be null. (Parameter 'variableName')", ex.Message); + Assert.That(ex!.Message, Does.Contain("Value cannot be null")); } [Test] public void Add_NullVariableName_ArgumentNullException() { // Act - var ex = Assert.Throws(() => _tpl.Add(null, "test")); + var ex = Assert.Throws(() => _tpl.Add(null!, "test")); // Assert - Assert.AreEqual("Value cannot be null. (Parameter 'variableName')", ex.Message); + Assert.That(ex!.Message, Does.Contain("Value cannot be null")); } [Test] @@ -55,13 +55,13 @@ public void Rollback_RolledAfterChange() _tpl.Set(VariableName, "test"); // Assert - Assert.AreEqual("test", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("test")); // Act _tpl.RollBack(); // Assert - Assert.AreEqual("{var1}", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("{var1}")); } [Test] @@ -71,9 +71,9 @@ public void GetAndRoll_RolledAfterChangeWithValueReturn() _tpl.Set(VariableName, "test"); // Act & Assert - Assert.AreEqual("test", _tpl.GetAndRoll()); + Assert.That(_tpl.GetAndRoll(), Is.EqualTo("test")); // Assert - Assert.AreEqual("{var1}", _tpl.Get()); + Assert.That(_tpl.Get(), Is.EqualTo("{var1}")); } } \ No newline at end of file diff --git a/src/Simplify.Templates.Tests/TestTemplates/Embedded/EmptyFIle.txt b/src/Simplify.Templates.Tests/TestTemplates/Embedded/EmptyFIle.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/Simplify.Templates.Tests/TestTemplates/Local/EmptyFIle.txt b/src/Simplify.Templates.Tests/TestTemplates/Local/EmptyFIle.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/Simplify.Templates/CHANGELOG.md b/src/Simplify.Templates/CHANGELOG.md index fcd89df9..3592d3a0 100644 --- a/src/Simplify.Templates/CHANGELOG.md +++ b/src/Simplify.Templates/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +### [2.0.2] - 2024-05-25 + +### Removed + +- Redundant null string check + +### Added + +- Some exceptions message + +### Changed + +- XML documentation refactoring +- Refactoring to new C# features + ## [2.0.1] - 2023-08-08 ### Removed diff --git a/src/Simplify.Templates/FileReader.cs b/src/Simplify.Templates/FileReader.cs index 1c13972d..43bb272a 100644 --- a/src/Simplify.Templates/FileReader.cs +++ b/src/Simplify.Templates/FileReader.cs @@ -5,7 +5,7 @@ namespace Simplify.Templates; /// -/// Provide files reader +/// Provides the file reader /// public static class FileReader { @@ -13,7 +13,6 @@ public static class FileReader /// Reads the file. /// /// The file path. - /// public static string ReadFile(string filePath) => File.ReadAllText(filePath); /// @@ -21,7 +20,6 @@ public static class FileReader /// /// The file path. /// The assembly. - /// /// Template: error loading file from resources in assembly '{assembly.FullName}': {filePath} public static string ReadFromAssembly(string filePath, Assembly assembly) { @@ -34,14 +32,14 @@ public static string ReadFromAssembly(string filePath, Assembly assembly) } /// - /// Reads from assembly asynchronous. + /// Reads the file from assembly asynchronous. /// /// The file path. /// The assembly. - /// /// Template: error loading file from resources in assembly '{assembly.FullName}': {filePath} public static async Task ReadFromAssemblyAsync(string filePath, Assembly assembly) { + // ReSharper disable once UseAwaitUsing using var fileStream = assembly.GetManifestResourceStream(filePath) ?? throw new TemplateException($"Error loading file from the assembly '{assembly.FullName}': {filePath}"); @@ -54,7 +52,6 @@ public static async Task ReadFromAssemblyAsync(string filePath, Assembly /// Reads the file asynchronously. /// /// The file path. - /// internal static async Task ReadFileAsync(string filePath) { using var sr = new StreamReader(filePath); diff --git a/src/Simplify.Templates/FileUtil.cs b/src/Simplify.Templates/FileUtil.cs index 1df90d8a..a45c7799 100644 --- a/src/Simplify.Templates/FileUtil.cs +++ b/src/Simplify.Templates/FileUtil.cs @@ -5,7 +5,7 @@ namespace Simplify.Templates; /// -/// Provides file utility class +/// Provides the file utility class /// public static class FileUtil { @@ -13,7 +13,6 @@ public static class FileUtil /// Constructs the full file path based on calling assembly location. /// /// The local file path. - /// public static string ConstructFullFilePath(string localFilePath) => $"{Path.GetDirectoryName(Assembly.GetCallingAssembly().Location)}/{localFilePath}"; /// @@ -21,7 +20,6 @@ public static class FileUtil /// /// The file path. /// The assembly. - /// public static string ConstructAssemblyFilePath(string filePath, Assembly assembly) { filePath = filePath.Replace("/", "."); @@ -35,11 +33,6 @@ public static string ConstructAssemblyFilePath(string filePath, Assembly assembl /// /// The file path. /// The assembly. - /// - public static bool AssemblyFileExists(string filePath, Assembly assembly) - { - var names = assembly.GetManifestResourceNames(); - - return names.Contains(filePath); - } + public static bool AssemblyFileExists(string filePath, Assembly assembly) => + assembly.GetManifestResourceNames().Contains(filePath); } \ No newline at end of file diff --git a/src/Simplify.Templates/ITemplate.cs b/src/Simplify.Templates/ITemplate.cs index 8af3b507..05d447ae 100644 --- a/src/Simplify.Templates/ITemplate.cs +++ b/src/Simplify.Templates/ITemplate.cs @@ -1,43 +1,41 @@ namespace Simplify.Templates; /// -/// Text templates interface +/// Represents a text template /// public interface ITemplate { /// - /// Set template variable value (all occurrences will be replaced) + /// Sets the template variable value (all occurrences will be replaced) /// - /// Variable name - /// Value to set + /// The variable name + /// The value to set ITemplate Set(string variableName, string? value); /// - /// Add value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable + /// Adds the value to the list to set to the template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable /// /// Variable name /// Value to set ITemplate Add(string variableName, string? value); /// - /// Get text of the template + /// Gets the text of the template /// string Get(); /// - /// Sets initial template state equal to current. + /// Sets the initial template state equal to current. /// - /// void Commit(); /// - /// Return template to it's initial state + /// Returns the template to it's initial state /// void RollBack(); /// /// Gets the text of the template and returns loaded template to it's initial state /// - /// Text of the template string GetAndRoll(); } \ No newline at end of file diff --git a/src/Simplify.Templates/Model/IModelSetter.cs b/src/Simplify.Templates/Model/IModelSetter.cs index 9a70efd6..c23be647 100644 --- a/src/Simplify.Templates/Model/IModelSetter.cs +++ b/src/Simplify.Templates/Model/IModelSetter.cs @@ -4,19 +4,18 @@ namespace Simplify.Templates.Model; /// -/// Represent model setter to template, sets all objects properties to template +/// Represents a model setter to template, sets all objects properties to template /// -/// Model type +/// The model type public interface IModelSetter where T : class { /// - /// Customizes specified property data set to template, for example, you can set custom expression to convert DateTime values + /// Customizes the specified property data set to template, for example, you can set custom expression to convert DateTime values /// /// The type of the data. /// The member expression. /// The data expression. - /// IModelSetter With(Expression> memberExpression, Func dataExpression); /// @@ -25,7 +24,7 @@ public interface IModelSetter ITemplate Set(); /// - /// Adds specified object (model) properties into template (adds to variables names like Model.MyPropertyName with respective object (model) properties values), values will be replaced on template Get or GetAndRoll methods call. + /// Adds the specified object (model) properties into template (adds to variables names like Model.MyPropertyName with respective object (model) properties values), values will be replaced on template Get or GetAndRoll methods call. /// ITemplate Add(); } \ No newline at end of file diff --git a/src/Simplify.Templates/Model/ModelSetter.cs b/src/Simplify.Templates/Model/ModelSetter.cs index e05318a0..d96e9a9f 100644 --- a/src/Simplify.Templates/Model/ModelSetter.cs +++ b/src/Simplify.Templates/Model/ModelSetter.cs @@ -5,54 +5,43 @@ namespace Simplify.Templates.Model; /// -/// Provides model setter to template, sets all objects properties to template +/// Provides the model setter to template, sets all objects properties to template /// -/// Model type -public class ModelSetter : ModelSetterBase, IModelSetter +/// The model type +/// +/// Initializes a new instance of the class. +/// +/// The template. +/// The model. +/// The model prefix. +public class ModelSetter(ITemplate template, T model, string? modelPrefix = null) : ModelSetterBase(template, modelPrefix), IModelSetter where T : class { - private readonly T _model; - private readonly Type _modelType; + private readonly Type _modelType = typeof(T); - private readonly IList _skipProperties = new List(); + private readonly IList _skipProperties = []; /// - /// Initializes a new instance of the class. - /// - /// The template. - /// The model. - /// The model prefix. - public ModelSetter(ITemplate template, T model, string? modelPrefix = null) - : base(template, modelPrefix) - { - _model = model; - - _modelType = typeof(T); - } - - /// - /// Customizes specified property data set to template, for example, you can set custom expression to convert DateTime values + /// Customizes the specified property data set to template, for example, you can set custom expression to convert DateTime values /// /// The type of the data. /// The member expression. /// The data expression. - /// /// memberExpression type is not a MemberExpression public IModelSetter With(Expression> memberExpression, Func dataExpression) { - var expression = memberExpression.Body as MemberExpression; - - if (expression == null) - throw new ArgumentException("memberExpression type is not a MemberExpression"); + var expression = memberExpression.Body as MemberExpression ?? throw new ArgumentException("memberExpression type is not a MemberExpression"); - if (_model == null) return this; + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract + if (model == null) + return this; _skipProperties.Add(expression.Member.Name); var propInfo = _modelType.GetProperty(expression.Member.Name); if (propInfo != null) - Template.Set(FormatModelVariableName(propInfo.Name), dataExpression.Invoke((TData)propInfo.GetValue(_model)!)); + Template.Set(FormatModelVariableName(propInfo.Name), dataExpression.Invoke((TData)propInfo.GetValue(model)!)); return this; } @@ -68,7 +57,7 @@ public ITemplate Set() { if (_skipProperties.Contains(propInfo.Name)) continue; - var value = _model == null ? null : propInfo.GetValue(_model); + var value = model == null ? null : propInfo.GetValue(model); Template.Set(FormatModelVariableName(propInfo.Name), value); } @@ -76,7 +65,7 @@ public ITemplate Set() } /// - /// Adds specified object (model) properties into template (adds to variables names like Model.MyPropertyName with respective object (model) properties values), values will be replaced on template Get or GetAndRoll methods call. + /// Adds the specified object (model) properties into template (adds to variables names like Model.MyPropertyName with respective object (model) properties values), values will be replaced on template Get or GetAndRoll methods call. /// public ITemplate Add() { @@ -86,7 +75,7 @@ public ITemplate Add() { if (_skipProperties.Contains(propInfo.Name)) continue; - var value = _model == null ? null : propInfo.GetValue(_model); + var value = model == null ? null : propInfo.GetValue(model); Template.Add(FormatModelVariableName(propInfo.Name), value); } diff --git a/src/Simplify.Templates/Model/ModelSetterBase.cs b/src/Simplify.Templates/Model/ModelSetterBase.cs index 9063a348..53e9a917 100644 --- a/src/Simplify.Templates/Model/ModelSetterBase.cs +++ b/src/Simplify.Templates/Model/ModelSetterBase.cs @@ -1,21 +1,15 @@ namespace Simplify.Templates.Model; /// -/// Provides ModelSetter base class +/// Provides the model setter base class /// -public abstract class ModelSetterBase +/// +/// Initializes a new instance of the class. +/// +/// The template. +/// The model prefix. +public abstract class ModelSetterBase(ITemplate template, string? modelPrefix = null) { - /// - /// Initializes a new instance of the class. - /// - /// The template. - /// The model prefix. - protected ModelSetterBase(ITemplate template, string? modelPrefix = null) - { - ModelPrefix = modelPrefix; - Template = template; - } - /// /// The model prefix separator /// @@ -24,20 +18,16 @@ protected ModelSetterBase(ITemplate template, string? modelPrefix = null) /// /// Gets the template. /// - /// - /// The template. - /// - public ITemplate Template { get; } + public ITemplate Template { get; } = template; /// - /// The model prefix + /// Gets the model prefix /// - protected string? ModelPrefix { get; } + protected string? ModelPrefix { get; } = modelPrefix; /// /// Formats the name of the variable to replace respecting model prefix. /// /// Name of the variable. - /// protected string FormatModelVariableName(string variableName) => ModelPrefix != null ? ModelPrefix + ModelPrefixSeparator + variableName : variableName; } \ No newline at end of file diff --git a/src/Simplify.Templates/Model/TemplateModelExtensions.cs b/src/Simplify.Templates/Model/TemplateModelExtensions.cs index dd89661d..66747eed 100644 --- a/src/Simplify.Templates/Model/TemplateModelExtensions.cs +++ b/src/Simplify.Templates/Model/TemplateModelExtensions.cs @@ -1,7 +1,7 @@ namespace Simplify.Templates.Model; /// -/// Template model extensions +/// Provides the template model extensions /// public static class TemplateModelExtensions { @@ -12,7 +12,6 @@ public static class TemplateModelExtensions /// The template. /// The model. /// The model prefix (for example 'Model', it will be used like 'Model.YourVariableName'). - /// public static IModelSetter Model(this ITemplate template, T model, string? modelPrefix = null) where T : class => new ModelSetter(template, model, modelPrefix); diff --git a/src/Simplify.Templates/Simplify.Templates.csproj b/src/Simplify.Templates/Simplify.Templates.csproj index a740df56..a0660cb4 100644 --- a/src/Simplify.Templates/Simplify.Templates.csproj +++ b/src/Simplify.Templates/Simplify.Templates.csproj @@ -8,7 +8,7 @@ snupkg true - 2.0.1 + 2.0.2 Alexander Krylkov Simplify diff --git a/src/Simplify.Templates/StringTable.cs b/src/Simplify.Templates/StringTable.cs index 68c40627..5793b0b3 100644 --- a/src/Simplify.Templates/StringTable.cs +++ b/src/Simplify.Templates/StringTable.cs @@ -10,7 +10,7 @@ namespace Simplify.Templates; /// -/// Provides string table related functionality +/// Provides the string table related functionality /// public static class StringTable { @@ -19,22 +19,16 @@ public static class StringTable /// /// The file path. /// The language code. - /// - public static string FormatStringTableFileName(string filePath, string languageCode) - { - return $"{filePath}.{languageCode}.xml"; - } + public static string FormatStringTableFileName(string filePath, string languageCode) => + $"{filePath}.{languageCode}.xml"; /// /// Formats the name of the assembly string table file. /// /// The file path. /// The language code. - /// - public static string FormatAssemblyStringTableFileName(string filePath, string languageCode) - { - return $"{filePath}-{languageCode}.xml"; - } + public static string FormatAssemblyStringTableFileName(string filePath, string languageCode) => + $"{filePath}-{languageCode}.xml"; /// /// Injects the string table items. @@ -51,7 +45,6 @@ public static void InjectStringTableItems(ITemplate tpl, IDictionary /// The string table XML. - /// public static IDictionary LoadStringTableFromString(string stringTableXml) { var stringTable = XDocument.Parse(stringTableXml); @@ -69,50 +62,34 @@ public static void InjectStringTableItems(ITemplate tpl, IDictionary /// The string table file path. /// The assembly. - /// - public static IDictionary LoadStringTableFromAssembly(string filePath, Assembly assembly) - { - return LoadStringTableFromString(FileReader.ReadFromAssembly(filePath, assembly)); - } + public static IDictionary LoadStringTableFromAssembly(string filePath, Assembly assembly) => + LoadStringTableFromString(FileReader.ReadFromAssembly(filePath, assembly)); /// /// Loads the string table from assembly embedded file asynchronously. /// /// The string table file path. /// The assembly. - /// - public static async Task> LoadStringTableFromAssemblyAsync(string filePath, Assembly assembly) - { - return LoadStringTableFromString(await FileReader.ReadFromAssemblyAsync(filePath, assembly)); - } + public static async Task> LoadStringTableFromAssemblyAsync(string filePath, Assembly assembly) => + LoadStringTableFromString(await FileReader.ReadFromAssemblyAsync(filePath, assembly)); /// /// Loads the string table from file. /// /// The string table file path. - /// - public static IDictionary LoadStringTableFromFile(string filePath) - { - return LoadStringTableFromString(FileReader.ReadFile(filePath)); - } + public static IDictionary LoadStringTableFromFile(string filePath) => + LoadStringTableFromString(FileReader.ReadFile(filePath)); /// /// Loads the string table from file asynchronously. /// /// The string table file path. - /// - public static async Task> LoadStringTableFromFileAsync(string filePath) - { - return LoadStringTableFromString(await FileReader.ReadFileAsync(filePath)); - } + public static async Task> LoadStringTableFromFileAsync(string filePath) => + LoadStringTableFromString(await FileReader.ReadFileAsync(filePath)); - private static string GetName(XElement item) - { - return (string?)item.Attribute("name") ?? throw new InvalidOperationException("name attribute is null"); - } + private static string GetName(XElement item) => + (string?)item.Attribute("name") ?? throw new InvalidOperationException("name attribute is null"); - private static string? GetValue(XElement item) - { - return string.IsNullOrEmpty(item.Value) ? (string?)item.Attribute("value") : item.InnerXml().Trim(); - } + private static string? GetValue(XElement item) => + string.IsNullOrEmpty(item.Value) ? (string?)item.Attribute("value") : item.InnerXml().Trim(); } \ No newline at end of file diff --git a/src/Simplify.Templates/Template.cs b/src/Simplify.Templates/Template.cs index 5d440a4d..85cd6e8b 100644 --- a/src/Simplify.Templates/Template.cs +++ b/src/Simplify.Templates/Template.cs @@ -4,30 +4,23 @@ namespace Simplify.Templates; /// -/// Text templates class +/// Provides the text template class /// -public class Template : ITemplate +/// +/// Initializes a new instance of the class. +/// +/// The text. +/// text +public class Template(string initialText) : ITemplate { - private string _initialText; - private string _text; + private string _text = initialText ?? throw new ArgumentNullException(nameof(initialText)); private IDictionary? _addValues; /// - /// Initializes a new instance of the class. + /// Sets the template variable value (all occurrences will be replaced) /// - /// The text. - /// text - public Template(string text) - { - _text = text ?? throw new ArgumentNullException(nameof(text)); - _initialText = text; - } - - /// - /// Set template variable value (all occurrences will be replaced) - /// - /// Variable name - /// Value to set + /// The variable name + /// The value to set public ITemplate Set(string variableName, string? value) { if (variableName == null) @@ -39,10 +32,11 @@ public ITemplate Set(string variableName, string? value) } /// - /// Add value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable + /// Adds the value to the list to set to the template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable /// /// Variable name /// Value to set + /// variableName public ITemplate Add(string variableName, string? value) { if (variableName == null) @@ -52,16 +46,21 @@ public ITemplate Add(string variableName, string? value) variableName = variableName.Trim(); +#if NET48 || NETSTANDARD2_0 if (!_addValues.ContainsKey(variableName)) _addValues.Add(variableName, value); else _addValues[variableName] = _addValues[variableName] + value; +#else + if (!_addValues.TryAdd(variableName, value)) + _addValues[variableName] += value; +#endif return this; } /// - /// Get text of the template + /// Gets the text of the template /// public string Get() { @@ -71,23 +70,22 @@ public string Get() } /// - /// Sets initial template state equal to current. + /// Sets the initial template state equal to current. /// - public void Commit() => _initialText = _text; + public void Commit() => initialText = _text; /// - /// Return template to it's initial state + /// Returns the template to it's initial state /// public void RollBack() { - _text = _initialText; + _text = initialText; _addValues?.Clear(); } /// /// Gets the text of the template and returns loaded template to it's initial state /// - /// Text of the template public string GetAndRoll() { var text = Get(); @@ -108,10 +106,5 @@ private void TryReplaceFromAddVariables() _addValues.Clear(); } - private void ReplaceWithValue(string variableName, string? value) - { - var replaceableVariable = "{" + variableName + "}"; - - _text = _text.Replace(replaceableVariable, value); - } + private void ReplaceWithValue(string variableName, string? value) => _text = _text.Replace("{" + variableName + "}", value); } \ No newline at end of file diff --git a/src/Simplify.Templates/TemplateAddExtensions.cs b/src/Simplify.Templates/TemplateAddExtensions.cs index 1c80e37b..f34c3706 100644 --- a/src/Simplify.Templates/TemplateAddExtensions.cs +++ b/src/Simplify.Templates/TemplateAddExtensions.cs @@ -3,61 +3,56 @@ namespace Simplify.Templates; /// -/// Template add method extensions +/// Provides the template add method extensions /// public static class TemplateAddExtensions { /// - /// Add value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable + /// Adds the value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// Tbe variable name + /// The value to set public static ITemplate Add(this ITemplate tpl, string variableName, int value) => tpl.Add(variableName, value.ToString(CultureInfo.InvariantCulture)); /// - /// Add value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable + /// Adds the value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// Tbe variable name + /// The value to set public static ITemplate Add(this ITemplate tpl, string variableName, object? value) => tpl.Add(variableName, value?.ToString()); /// - /// Add value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable + /// Adds the value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable /// - /// The TPL. - /// Variable name - /// Value to set + /// The template. + /// Tbe variable name + /// The value to set /// public static ITemplate Add(this ITemplate tpl, string variableName, double value) => tpl.Add(variableName, value.ToString(CultureInfo.InvariantCulture)); /// - /// Add value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable + /// Adds the value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// Tbe variable name + /// The value to set public static ITemplate Add(this ITemplate tpl, string variableName, decimal value) => tpl.Add(variableName, value.ToString(CultureInfo.InvariantCulture)); /// - /// Add value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable + /// Adds the value to set template variable value (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// Tbe variable name + /// The value to set public static ITemplate Add(this ITemplate tpl, string variableName, long value) => tpl.Add(variableName, value.ToString(CultureInfo.InvariantCulture)); /// - /// Add value to set template variable value with text from template (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable + /// Adds the value to set template variable value with text from template (all occurrences will be replaced on Get method execute) allows setting multiple values to template variable /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// Tbe variable name + /// The value to set public static ITemplate Add(this ITemplate tpl, string variableName, ITemplate template) => tpl.Add(variableName, template?.Get()); } \ No newline at end of file diff --git a/src/Simplify.Templates/TemplateBuilder.cs b/src/Simplify.Templates/TemplateBuilder.cs index 9b565f7b..dc0acf05 100644 --- a/src/Simplify.Templates/TemplateBuilder.cs +++ b/src/Simplify.Templates/TemplateBuilder.cs @@ -7,7 +7,7 @@ namespace Simplify.Templates; /// -/// Provides ITemplate fluent builder +/// Provides the template fluent builder /// public class TemplateBuilder { @@ -23,10 +23,9 @@ private TemplateBuilder() } /// - /// Create builder based on the string. + /// Creates the builder based on the string. /// /// The text. - /// public static TemplateBuilder FromString(string text) { if (text == null) @@ -39,10 +38,9 @@ public static TemplateBuilder FromString(string text) } /// - /// Create builder based on the file path, accepted full path or relative path according to current working directory. + /// Creates the builder based on the file path, accepted full path or relative path according to current working directory. /// /// The file path. - /// public static TemplateBuilder FromFile(string filePath) { if (string.IsNullOrEmpty(filePath)) @@ -57,10 +55,9 @@ public static TemplateBuilder FromFile(string filePath) } /// - /// Create builder based on the file using calling assembly path prefix in filePath. + /// Creates the builder based on the file using calling assembly path prefix in filePath. /// /// The file path. - /// public static TemplateBuilder FromLocalFile(string filePath) { if (string.IsNullOrEmpty(filePath)) @@ -77,11 +74,10 @@ public static TemplateBuilder FromLocalFile(string filePath) } /// - /// Creates builder based on specified assembly embedded file, filePath should be path of the file inside assembly. + /// Creates the builder based on specified assembly embedded file, filePath should be path of the file inside assembly. /// /// The file path. /// The assembly. - /// /// public static TemplateBuilder FromAssembly(string filePath, Assembly assembly) { @@ -103,10 +99,9 @@ public static TemplateBuilder FromAssembly(string filePath, Assembly assembly) } /// - /// Creates builder based on the calling assembly embedded file, filePath should be path of the file inside assembly. + /// Creates the builder based on the calling assembly embedded file, filePath should be path of the file inside assembly. /// /// The file path. - /// /// public static TemplateBuilder FromCurrentAssembly(string filePath) { @@ -128,14 +123,10 @@ public static TemplateBuilder FromCurrentAssembly(string filePath) /// /// Builds the template. /// - /// public ITemplate Build() { var text = LoadTemplateText(); - if (text == null) - throw new TemplateException("Can't initialize empty template"); - text = PreprocessTemplateText(text); var tpl = new Template(text); @@ -148,14 +139,10 @@ public ITemplate Build() /// /// Builds the template asynchronously. /// - /// public async Task BuildAsync() { var text = await LoadTemplateTextAsync(); - if (text == null) - throw new TemplateException("Can't initialize empty template"); - PreprocessTemplateText(text); var tpl = new Template(text); @@ -170,7 +157,6 @@ public async Task BuildAsync() /// /// The language. /// The base language. - /// public TemplateBuilder Localizable(string language, string baseLanguage = "en") { if (string.IsNullOrEmpty(language)) @@ -189,7 +175,6 @@ public TemplateBuilder Localizable(string language, string baseLanguage = "en") /// Localizes the template from xml localization files using Thread.CurrentThread culture language as default. /// /// The base language. - /// public TemplateBuilder LocalizableFromCurrentThreadLanguage(string baseLanguage = "en") { if (string.IsNullOrEmpty(baseLanguage)) @@ -204,7 +189,6 @@ public TemplateBuilder LocalizableFromCurrentThreadLanguage(string baseLanguage /// /// Replace all caret return characters by html ]]> tag. /// - /// public TemplateBuilder FixLineEndingsHtml() { _fixLineEndingsHtml = true; @@ -232,7 +216,7 @@ private string LoadTemplateText() return _text; if (_filePath == null) - throw new InvalidOperationException(); + throw new InvalidOperationException("File path is null"); return _assembly == null ? FileReader.ReadFile(_filePath) @@ -245,7 +229,7 @@ private async Task LoadTemplateTextAsync() return _text; if (_filePath == null) - throw new InvalidOperationException(); + throw new InvalidOperationException("File path is null"); return _assembly == null ? await FileReader.ReadFileAsync(_filePath) diff --git a/src/Simplify.Templates/TemplateException.cs b/src/Simplify.Templates/TemplateException.cs index 703b226f..1871658d 100644 --- a/src/Simplify.Templates/TemplateException.cs +++ b/src/Simplify.Templates/TemplateException.cs @@ -3,14 +3,12 @@ namespace Simplify.Templates; /// -/// provides `Template` related exceptions +/// Provides the template related exceptions /// -[Serializable] -public sealed class TemplateException : Exception +/// +/// Initializes a new instance of the class. +/// +/// The message that describes the error. +public sealed class TemplateException(string message) : Exception(message) { - /// - /// Initializes a new instance of the class. - /// - /// The message that describes the error. - public TemplateException(string message) : base(message) { } } \ No newline at end of file diff --git a/src/Simplify.Templates/TemplateLocalizeExtensions.cs b/src/Simplify.Templates/TemplateLocalizeExtensions.cs index 9c2bb340..8b674d35 100644 --- a/src/Simplify.Templates/TemplateLocalizeExtensions.cs +++ b/src/Simplify.Templates/TemplateLocalizeExtensions.cs @@ -5,17 +5,18 @@ namespace Simplify.Templates; /// -/// Providers template localization extensions +/// Providers the template localization extensions /// public static class TemplateLocalizeExtensions { /// /// Localizes the specified template. /// - /// The TPL. + /// The template. /// The template file path. /// The language. /// The base language. + // ReSharper disable once TooManyArguments public static void Localize(this ITemplate tpl, string filePath, string language, string baseLanguage) { var currentCultureStringTableFilePath = StringTable.FormatStringTableFileName(filePath, language); @@ -31,12 +32,13 @@ public static void Localize(this ITemplate tpl, string filePath, string language } /// - /// Localizes the specified template the asynchronously. + /// Localizes the specified template asynchronously. /// - /// The TPL. + /// The template. /// The template file path. /// The language. /// The base language. + // ReSharper disable once TooManyArguments public static async Task LocalizeAsync(this ITemplate tpl, string filePath, string language, string baseLanguage) { var currentCultureStringTableFilePath = StringTable.FormatStringTableFileName(filePath, language); @@ -54,11 +56,12 @@ public static async Task LocalizeAsync(this ITemplate tpl, string filePath, stri /// /// Localizes the specified template from the assembly. /// - /// The TPL. + /// The template. /// The file path. /// The assembly. /// The language. /// The base language. + // ReSharper disable once TooManyArguments public static void LocalizeFromAssembly(this ITemplate tpl, string filePath, Assembly assembly, string language, string baseLanguage) { var currentCultureStringTableFilePath = StringTable.FormatAssemblyStringTableFileName(filePath, language); @@ -76,11 +79,12 @@ public static void LocalizeFromAssembly(this ITemplate tpl, string filePath, Ass /// /// Localizes the specified template from the assembly asynchronously. /// - /// The TPL. + /// The template. /// The file path. /// The assembly. /// The language. /// The base language. + // ReSharper disable once TooManyArguments public static async Task LocalizeFromAssemblyAsync(this ITemplate tpl, string filePath, Assembly assembly, string language, string baseLanguage) { var currentCultureStringTableFilePath = StringTable.FormatAssemblyStringTableFileName(filePath, language); diff --git a/src/Simplify.Templates/TemplateSetExtensions.cs b/src/Simplify.Templates/TemplateSetExtensions.cs index b040337d..aa8ce199 100644 --- a/src/Simplify.Templates/TemplateSetExtensions.cs +++ b/src/Simplify.Templates/TemplateSetExtensions.cs @@ -3,61 +3,55 @@ namespace Simplify.Templates; /// -/// Template set method extensions +/// Provides the template set method extensions /// public static class TemplateSetExtensions { /// - /// Set template variable value with text from template (all occurrences will be replaced) + /// Sets the template variable value with text from template (all occurrences will be replaced) /// /// Value to set - /// Variable name + /// The variable name /// The template. - /// public static ITemplate Set(this ITemplate tpl, string variableName, ITemplate template) => tpl.Set(variableName, template?.Get()); /// - /// Set template variable value (all occurrences will be replaced) + /// Sets the template variable value (all occurrences will be replaced) /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// The variable name + /// The value to set public static ITemplate Set(this ITemplate tpl, string variableName, object? value) => tpl.Set(variableName, value?.ToString()); /// - /// Set template variable value (all occurrences will be replaced) + /// Sets the template variable value (all occurrences will be replaced) /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// The variable name + /// The value to set public static ITemplate Set(this ITemplate tpl, string variableName, int value) => tpl.Set(variableName, value.ToString(CultureInfo.InvariantCulture)); /// - /// Set template variable value (all occurrences will be replaced) + /// Sets the template variable value (all occurrences will be replaced) /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// The variable name + /// The value to set public static ITemplate Set(this ITemplate tpl, string variableName, long value) => tpl.Set(variableName, value.ToString(CultureInfo.InvariantCulture)); /// - /// Set template variable value (all occurrences will be replaced) + /// Sets the template variable value (all occurrences will be replaced) /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// The variable name + /// The value to set public static ITemplate Set(this ITemplate tpl, string variableName, decimal value) => tpl.Set(variableName, value.ToString(CultureInfo.InvariantCulture)); /// - /// Set template variable value (all occurrences will be replaced) + /// Sets the template variable value (all occurrences will be replaced) /// - /// The TPL. - /// Variable name - /// Value to set - /// + /// The template. + /// The variable name + /// The value to set public static ITemplate Set(this ITemplate tpl, string variableName, double value) => tpl.Set(variableName, value.ToString(CultureInfo.InvariantCulture)); } \ No newline at end of file