#11: update setValue method to handle enumerables

pull/26/head
Simon Gockner 6 years ago
parent 6aeffa85ee
commit 0f9531cfb5
  1. 10
      GBase/DataHandling/XmlDataHandler.cs
  2. 7
      GBase/GBase.xml
  3. 2
      Test.GBase/DataHandling/XmlDataHandlerTest.cs

@ -3,12 +3,14 @@
// Copyright(c) 2020 SimonG. All Rights Reserved. // Copyright(c) 2020 SimonG. All Rights Reserved.
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using GBase.DataHandling.Cache.Factories; using GBase.DataHandling.Cache.Factories;
using GBase.DataHandling.Factories; using GBase.DataHandling.Factories;
using GBase.Helpers;
using GBase.Interfaces.DataHandling; using GBase.Interfaces.DataHandling;
using GBase.Interfaces.DataHandling.Xml; using GBase.Interfaces.DataHandling.Xml;
using GBase.Interfaces.DataHandling.Xml.Cache; using GBase.Interfaces.DataHandling.Xml.Cache;
@ -97,8 +99,14 @@ namespace GBase.DataHandling
if (value == null) if (value == null)
return; return;
string valueString;
if (typeof(TProperty) != typeof(string) && value is IEnumerable enumerable)
valueString = enumerable.ToGBaseString();
else
valueString = value.ToString();
await _cache.SetValue<T, TProperty>(propertyName, value, _overwrite); await _cache.SetValue<T, TProperty>(propertyName, value, _overwrite);
await _xmlDataWriter.Write<T, TProperty>(propertyName, value.ToString(), _overwrite); await _xmlDataWriter.Write<T, TProperty>(propertyName, valueString, _overwrite);
} }
/// <summary> /// <summary>

@ -532,6 +532,13 @@
</summary> </summary>
<returns>A <see cref="T:System.Threading.Tasks.ValueTask"/> to await</returns> <returns>A <see cref="T:System.Threading.Tasks.ValueTask"/> to await</returns>
</member> </member>
<member name="M:GBase.Helpers.Enumerables.ToGBaseString(System.Collections.IEnumerable)">
<summary>
Convert an <see cref="T:System.Collections.IEnumerable"/> to a GBase <see cref="T:System.String"/>
</summary>
<param name="enumerable">The <see cref="T:System.Collections.IEnumerable"/></param>
<returns></returns>
</member>
<member name="T:GBase.Installers.DataHandlingInstaller"> <member name="T:GBase.Installers.DataHandlingInstaller">
<summary> <summary>
<see cref="T:LightweightIocContainer.Interfaces.Installers.IIocInstaller"/> for the data handling <see cref="T:LightweightIocContainer.Interfaces.Installers.IIocInstaller"/> for the data handling

@ -165,7 +165,7 @@ namespace Test.GBase.DataHandling
await xmlDataHandler.SetValue<XmlDataHandlerTest, List<string>>("property", stringList); await xmlDataHandler.SetValue<XmlDataHandlerTest, List<string>>("property", stringList);
xmlDataHandlerCacheMock.Verify(c => c.SetValue<XmlDataHandlerTest, List<string>>("property", stringList, false), Times.Once); xmlDataHandlerCacheMock.Verify(c => c.SetValue<XmlDataHandlerTest, List<string>>("property", stringList, false), Times.Once);
xmlDataWriterMock.Verify(w => w.Write<XmlDataHandlerTest, List<string>>("property", $"{stringList[0]}, {stringList[1]}, {stringList[2]}", false), Times.Once); xmlDataWriterMock.Verify(w => w.Write<XmlDataHandlerTest, List<string>>("property", $"{stringList[0]},{stringList[1]},{stringList[2]}", false), Times.Once);
} }
[Test] [Test]

Loading…
Cancel
Save