You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
698 B
27 lines
698 B
// Author: Gockner, Simon
|
|
// Created: 2021-04-27
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved.
|
|
|
|
using System.IO;
|
|
using System.Xml;
|
|
using System.Xml.Serialization;
|
|
using Lib.Xml.Interfaces;
|
|
|
|
namespace Lib.Xml
|
|
{
|
|
public class XmlReader<T> : IXmlReader<T> where T : new()
|
|
{
|
|
public T Read(string filePath)
|
|
{
|
|
if (!File.Exists(filePath))
|
|
return new T();
|
|
|
|
FileStream file = File.OpenRead(filePath);
|
|
|
|
XmlReader xmlReader = XmlReader.Create(file);
|
|
XmlSerializer xmlSerializer = new(typeof(T));
|
|
|
|
return (T?) xmlSerializer.Deserialize(xmlReader) ?? new T();
|
|
}
|
|
}
|
|
} |