- inject GBase, prepare for new Enumerables

master
Simon G 5 years ago
parent 700d71cc9d
commit 9a058caade
  1. 13
      GBase/DataHandling/XmlDataReader.cs

@ -12,16 +12,25 @@ using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using GBase.DataHandling.Exceptions; using GBase.DataHandling.Exceptions;
using GBase.Helpers; using GBase.Helpers;
using GBase.Interfaces;
using GBase.Interfaces.DataHandling; using GBase.Interfaces.DataHandling;
using GBase.Interfaces.DataHandling.Xml; using GBase.Interfaces.DataHandling.Xml;
namespace GBase.DataHandling namespace GBase.DataHandling
{ {
/// <summary> /// <summary>
/// A <see cref="IDataReader"/> that reads from a xml file /// An <see cref="IDataReader"/> that reads from a xml file
/// </summary> /// </summary>
public class XmlDataReader : IXmlDataReader public class XmlDataReader : IXmlDataReader
{ {
private readonly IGBase _gBase;
/// <summary>
/// An <see cref="IDataReader"/> that reads from a xml file
/// </summary>
/// <param name="gBase">The <see cref="IGBase"/></param>
public XmlDataReader(IGBase gBase) => _gBase = gBase;
/// <summary> /// <summary>
/// Read the data of a property /// Read the data of a property
/// </summary> /// </summary>
@ -66,7 +75,7 @@ namespace GBase.DataHandling
IEnumerable<string> values = valueElements.Select(v => v.Value); IEnumerable<string> values = valueElements.Select(v => v.Value);
if (typeof(TProperty) != typeof(string) && typeof(TProperty).GetInterfaces().Contains(typeof(IEnumerable))) //read property is an IEnumerable if (typeof(TProperty) != typeof(string) && typeof(TProperty).GetInterfaces().Contains(typeof(IEnumerable))) //read property is an IEnumerable
return values.Select(Enumerables.ConvertToGBaseEnumerable<TProperty>).ToList(); return values.Select(s => Enumerables.ConvertToGBaseEnumerable<TProperty>(s, _gBase)).ToList();
return values.Select(value => (TProperty) Convert.ChangeType(value, typeof(TProperty))).ToList(); return values.Select(value => (TProperty) Convert.ChangeType(value, typeof(TProperty))).ToList();
}, cancellationToken); }, cancellationToken);

Loading…
Cancel
Save