public void WriteConfiguration(AppConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var configurationFile = fileLocator.LocateFile(); using var writer = XmlWriter.Create(configurationFile, new XmlWriterSettings { Indent = true }); var serializer = new DataContractSerializer(typeof(AppConfiguration)); serializer.WriteObject(writer, configuration); }
public AppConfiguration ReadConfiguration() { var configurationFile = fileLocator.LocateFile(); try { using var reader = XmlReader.Create(configurationFile); var serializer = new DataContractSerializer(typeof(AppConfiguration)); return((AppConfiguration)serializer.ReadObject(reader)); } catch (FileNotFoundException) { return(null); } catch (Exception e) when(e is XmlException || e is SerializationException) { logger.LogError(e, "Failed to read configuration file"); return(null); } }