diff --git a/INIWrapper/IniWrapper/IniWrapper.csproj b/INIWrapper/IniWrapper/IniWrapper.csproj
index 392eb1c..bc5d55f 100644
--- a/INIWrapper/IniWrapper/IniWrapper.csproj
+++ b/INIWrapper/IniWrapper/IniWrapper.csproj
@@ -11,8 +11,7 @@
true
Piotr Szkudlarski
2019 Piotr Szkudlarski
- Breaking change:
-- Fixed Key and Section evaluation in Enumerable of complex type
+ - Support DateTime, TimeSpan, DateTimeOffset, Guid, Uri
4.0.0.0
Debug;Release;ReleaseBenchmark
diff --git a/IniWrapper/IniWrapper.ModuleTests/Main/Configuration/Properties/GuidConfiguration.cs b/IniWrapper/IniWrapper.ModuleTests/Main/Configuration/Properties/GuidConfiguration.cs
new file mode 100644
index 0000000..caecc2e
--- /dev/null
+++ b/IniWrapper/IniWrapper.ModuleTests/Main/Configuration/Properties/GuidConfiguration.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace IniWrapper.ModuleTests.Main.Configuration.Properties
+{
+ public class GuidConfiguration
+ {
+ public Guid Guid { get; set; }
+ public Uri Uri { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper.ModuleTests/Main/Configuration/Properties/TimeConfiguration.cs b/IniWrapper/IniWrapper.ModuleTests/Main/Configuration/Properties/TimeConfiguration.cs
new file mode 100644
index 0000000..7dd7087
--- /dev/null
+++ b/IniWrapper/IniWrapper.ModuleTests/Main/Configuration/Properties/TimeConfiguration.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace IniWrapper.ModuleTests.Main.Configuration.Properties
+{
+ public class TimeConfiguration
+ {
+ public DateTime DateTime { get; set; }
+
+ public TimeSpan TimeSpan { get; set; }
+
+ public DateTimeOffset DateTimeOffset { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper.ModuleTests/Main/Read/Properties/IniWrapperReadGuidConfigurationTests.cs b/IniWrapper/IniWrapper.ModuleTests/Main/Read/Properties/IniWrapperReadGuidConfigurationTests.cs
new file mode 100644
index 0000000..ee2c955
--- /dev/null
+++ b/IniWrapper/IniWrapper.ModuleTests/Main/Read/Properties/IniWrapperReadGuidConfigurationTests.cs
@@ -0,0 +1,44 @@
+using System;
+using FluentAssertions;
+using IniWrapper.ModuleTests.Main.Configuration.Properties;
+using IniWrapper.ModuleTests.MockParser;
+using IniWrapper.ParserWrapper;
+using IniWrapper.Wrapper;
+using NSubstitute;
+using NUnit.Framework;
+
+namespace IniWrapper.ModuleTests.Main.Read.Properties
+{
+ [TestFixture]
+ public class IniWrapperReadGuidConfigurationTests
+ {
+ private IIniWrapper _iniWrapper;
+
+ private IIniParser _iniParser;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _iniParser = Substitute.For();
+ _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser);
+ }
+
+ [Test]
+ public void LoadConfiguration_ShouldLoadGuid()
+ {
+ var configuration = new GuidConfiguration()
+ {
+ Guid = Guid.NewGuid(),
+ Uri = new Uri("http://testttt.com/")
+ };
+
+ _iniParser.Read(nameof(GuidConfiguration), nameof(GuidConfiguration.Guid)).Returns(configuration.Guid.ToString());
+ _iniParser.Read(nameof(GuidConfiguration), nameof(GuidConfiguration.Uri)).Returns(configuration.Uri.ToString());
+
+ var result = _iniWrapper.LoadConfiguration();
+
+ result.Guid.Should().Be(configuration.Guid);
+ result.Uri.Should().Be(configuration.Uri);
+ }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper.ModuleTests/Main/Read/Properties/IniWrapperReadTimeConfigurationTests.cs b/IniWrapper/IniWrapper.ModuleTests/Main/Read/Properties/IniWrapperReadTimeConfigurationTests.cs
new file mode 100644
index 0000000..0cc1fba
--- /dev/null
+++ b/IniWrapper/IniWrapper.ModuleTests/Main/Read/Properties/IniWrapperReadTimeConfigurationTests.cs
@@ -0,0 +1,44 @@
+using System;
+using FluentAssertions;
+using IniWrapper.ModuleTests.Main.Configuration.Properties;
+using IniWrapper.ModuleTests.MockParser;
+using IniWrapper.ParserWrapper;
+using IniWrapper.Wrapper;
+using NSubstitute;
+using NUnit.Framework;
+
+namespace IniWrapper.ModuleTests.Main.Read.Properties
+{
+ [TestFixture]
+ public class IniWrapperReadTimeConfigurationTests
+ {
+ private IIniWrapper _iniWrapper;
+
+ private IIniParser _iniParser;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _iniParser = Substitute.For();
+ _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser);
+ }
+
+ [Test]
+ public void LoadConfiguration_ShouldLoadDateTimeAndTimeSpan()
+ {
+ var dateTime = new DateTime(2019, 02, 07, 18, 58, 58);
+ var timeSpan = new TimeSpan(10, 10, 10);
+ var datetimeOffset = new DateTimeOffset(2019, 02, 07, 18, 58,10,TimeSpan.FromMinutes(20));
+
+ _iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTime)).Returns(dateTime.ToString("O"));
+ _iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.TimeSpan)).Returns(timeSpan.ToString());
+ _iniParser.Read(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTimeOffset)).Returns(datetimeOffset.ToString());
+
+ var result = _iniWrapper.LoadConfiguration();
+
+ result.DateTime.Should().Be(dateTime);
+ result.TimeSpan.Should().Be(timeSpan);
+ result.DateTimeOffset.Should().Be(datetimeOffset);
+ }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper.ModuleTests/Main/Save/Properties/IniWrapperSaveGuidConfigurationTests.cs b/IniWrapper/IniWrapper.ModuleTests/Main/Save/Properties/IniWrapperSaveGuidConfigurationTests.cs
new file mode 100644
index 0000000..2764381
--- /dev/null
+++ b/IniWrapper/IniWrapper.ModuleTests/Main/Save/Properties/IniWrapperSaveGuidConfigurationTests.cs
@@ -0,0 +1,39 @@
+using System;
+using IniWrapper.ModuleTests.Main.Configuration.Properties;
+using IniWrapper.ModuleTests.MockParser;
+using IniWrapper.ParserWrapper;
+using IniWrapper.Wrapper;
+using NSubstitute;
+using NUnit.Framework;
+
+namespace IniWrapper.ModuleTests.Main.Save.Properties
+{
+ [TestFixture]
+ public class IniWrapperSaveGuidConfigurationTests
+ {
+ private IIniWrapper _iniWrapper;
+
+ private IIniParser _iniParser;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _iniParser = Substitute.For();
+ _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser);
+ }
+
+ [Test]
+ public void SaveConfiguration_ShouldSaveCorrectWriteDateTime_And_TimeSpan()
+ {
+ var config = new GuidConfiguration()
+ {
+ Guid = Guid.NewGuid(),
+ Uri = new Uri("http://testttt.com/")
+ };
+
+ _iniWrapper.SaveConfiguration(config);
+ _iniParser.Received(1).Write(nameof(GuidConfiguration), nameof(GuidConfiguration.Guid), config.Guid.ToString());
+ _iniParser.Received(1).Write(nameof(GuidConfiguration), nameof(GuidConfiguration.Uri), config.Uri.ToString());
+ }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper.ModuleTests/Main/Save/Properties/IniWrapperSaveTimeConfigurationTests.cs b/IniWrapper/IniWrapper.ModuleTests/Main/Save/Properties/IniWrapperSaveTimeConfigurationTests.cs
new file mode 100644
index 0000000..d94754d
--- /dev/null
+++ b/IniWrapper/IniWrapper.ModuleTests/Main/Save/Properties/IniWrapperSaveTimeConfigurationTests.cs
@@ -0,0 +1,42 @@
+using IniWrapper.ModuleTests.Main.Configuration.Properties;
+using IniWrapper.ModuleTests.MockParser;
+using IniWrapper.ParserWrapper;
+using IniWrapper.Wrapper;
+using NSubstitute;
+using NUnit.Framework;
+using System;
+
+namespace IniWrapper.ModuleTests.Main.Save.Properties
+{
+ [TestFixture]
+ public class IniWrapperSaveTimeConfigurationTests
+ {
+ private IIniWrapper _iniWrapper;
+
+ private IIniParser _iniParser;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _iniParser = Substitute.For();
+ _iniWrapper = MockWrapperFactory.CreateWithFileSystem(_iniParser);
+ }
+
+ [Test]
+ public void SaveConfiguration_ShouldSaveCorrectWriteDateTime_And_TimeSpan()
+ {
+ var config = new TimeConfiguration()
+ {
+ DateTime = new DateTime(2019, 02, 07, 18, 58, 58),
+ TimeSpan = new TimeSpan(10, 10, 10),
+ DateTimeOffset = new DateTimeOffset(2019, 02, 07, 18, 58, 10, TimeSpan.FromMinutes(20))
+ };
+
+ _iniWrapper.SaveConfiguration(config);
+
+ _iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTime), config.DateTime.ToString("O"));
+ _iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.TimeSpan), config.TimeSpan.ToString());
+ _iniParser.Received(1).Write(nameof(TimeConfiguration), nameof(TimeConfiguration.DateTimeOffset), config.DateTimeOffset.ToString());
+ }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper/ConverterFactory/IniConverterFactory.cs b/IniWrapper/IniWrapper/ConverterFactory/IniConverterFactory.cs
index 69fc91c..323ea5a 100644
--- a/IniWrapper/IniWrapper/ConverterFactory/IniConverterFactory.cs
+++ b/IniWrapper/IniWrapper/ConverterFactory/IniConverterFactory.cs
@@ -14,6 +14,9 @@
using IniWrapper.Wrapper;
using IniWrapper.Wrapper.CustomMemberFactory;
using System;
+using IniWrapper.Converters.Guid;
+using IniWrapper.Converters.Time;
+using IniWrapper.Converters.Uri;
using TypeCode = IniWrapper.Utils.TypeCode;
namespace IniWrapper.ConverterFactory
@@ -131,6 +134,31 @@ private IIniConverter GetBaseHandler(TypeCode typeCode, bool? isEnum)
return new EnumConverter(typeCode);
}
+ if (typeCode == TypeCode.DateTime)
+ {
+ return new DateTimeConverter();
+ }
+
+ if (typeCode == TypeCode.TimeSpan)
+ {
+ return new TimeSpanConverter();
+ }
+
+ if (typeCode == TypeCode.Guid)
+ {
+ return new GuidConverter();
+ }
+
+ if (typeCode == TypeCode.DateTimeOffset)
+ {
+ return new DateTimeOffsetConverter();
+ }
+
+ if (typeCode == TypeCode.Uri)
+ {
+ return new UriConverter();
+ }
+
return new PrimitivesConverter();
}
}
diff --git a/IniWrapper/IniWrapper/Converters/Guid/GuidConverter.cs b/IniWrapper/IniWrapper/Converters/Guid/GuidConverter.cs
new file mode 100644
index 0000000..1d1fdd3
--- /dev/null
+++ b/IniWrapper/IniWrapper/Converters/Guid/GuidConverter.cs
@@ -0,0 +1,19 @@
+using System;
+using IniWrapper.Manager;
+
+namespace IniWrapper.Converters.Guid
+{
+ public class GuidConverter : IIniConverter
+ {
+ public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext)
+ {
+ return System.Guid.Parse(readValue);
+ }
+
+ public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
+ {
+ iniContext.IniValue.Value = objectToFormat.ToString();
+ return iniContext.IniValue;
+ }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper/Converters/Time/DateTimeConverter.cs b/IniWrapper/IniWrapper/Converters/Time/DateTimeConverter.cs
new file mode 100644
index 0000000..1095ba4
--- /dev/null
+++ b/IniWrapper/IniWrapper/Converters/Time/DateTimeConverter.cs
@@ -0,0 +1,20 @@
+using System;
+using IniWrapper.Manager;
+
+namespace IniWrapper.Converters.Time
+{
+ public class DateTimeConverter : IIniConverter
+ {
+ public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext)
+ {
+ return DateTime.Parse(readValue);
+ }
+
+ public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
+ {
+ var dateTime = (DateTime) objectToFormat;
+ iniContext.IniValue.Value = dateTime.ToString("O");
+ return iniContext.IniValue;
+ }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper/Converters/Time/DateTimeOffsetConverter.cs b/IniWrapper/IniWrapper/Converters/Time/DateTimeOffsetConverter.cs
new file mode 100644
index 0000000..bb69254
--- /dev/null
+++ b/IniWrapper/IniWrapper/Converters/Time/DateTimeOffsetConverter.cs
@@ -0,0 +1,19 @@
+using System;
+using IniWrapper.Manager;
+
+namespace IniWrapper.Converters.Time
+{
+ public class DateTimeOffsetConverter : IIniConverter
+ {
+ public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext)
+ {
+ return DateTimeOffset.Parse(readValue);
+ }
+
+ public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
+ {
+ iniContext.IniValue.Value = objectToFormat.ToString();
+ return iniContext.IniValue;
+ }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper/Converters/Time/TimeSpanConverter.cs b/IniWrapper/IniWrapper/Converters/Time/TimeSpanConverter.cs
new file mode 100644
index 0000000..e8aa24e
--- /dev/null
+++ b/IniWrapper/IniWrapper/Converters/Time/TimeSpanConverter.cs
@@ -0,0 +1,19 @@
+using System;
+using IniWrapper.Manager;
+
+namespace IniWrapper.Converters.Time
+{
+ public class TimeSpanConverter : IIniConverter
+ {
+ public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext)
+ {
+ return TimeSpan.Parse(readValue);
+ }
+
+ public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
+ {
+ iniContext.IniValue.Value = objectToFormat.ToString();
+ return iniContext.IniValue;
+ }
+ }
+}
\ No newline at end of file
diff --git a/IniWrapper/IniWrapper/Converters/Uri/UriConverter.cs b/IniWrapper/IniWrapper/Converters/Uri/UriConverter.cs
new file mode 100644
index 0000000..366fdd0
--- /dev/null
+++ b/IniWrapper/IniWrapper/Converters/Uri/UriConverter.cs
@@ -0,0 +1,19 @@
+using System;
+using IniWrapper.Manager;
+
+namespace IniWrapper.Converters.Uri
+{
+ public class UriConverter : IIniConverter
+ {
+ public object ParseReadValue(string readValue, Type destinationType, IniContext iniContext)
+ {
+ return new System.Uri(readValue);
+ }
+
+ public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
+ {
+ iniContext.IniValue.Value = objectToFormat.ToString();
+ return iniContext.IniValue;
+ }
+ }
+}
\ No newline at end of file