NanoByte.Common
Static Public Member Functions | Static Public Attributes | List of all members
NanoByte.Common.Storage.XmlStorage Class Reference

Provides easy serialization to XML files (optionally wrapped in ZIP archives). More...

Static Public Member Functions

static T LoadXml< T > (Stream stream)
 Loads an object from an XML file. More...
 
static T LoadXml< T > ([Localizable(false)] string path)
 Loads an object from an XML file. More...
 
static T FromXmlString< T > ([Localizable(false)] string data)
 Loads an object from an XML string. More...
 
static void SaveXml< T > (this T data, Stream stream, [Localizable(false)] string? stylesheet=null)
 Saves an object in an XML stream ending with a line break. More...
 
static void SaveXml< T > (this T data, [Localizable(false)] string path, [Localizable(false)] string? stylesheet=null)
 Saves an object in an XML file ending with a line break. More...
 
static string ToXmlString< T > (this T data, [Localizable(false)] string? stylesheet=null)
 Returns an object as an XML string ending with a line break. More...
 

Static Public Attributes

const string XsiNamespace = "http://www.w3.org/2001/XMLSchema-instance"
 The XML namespace used for XML Schema instance. More...
 

Detailed Description

Provides easy serialization to XML files (optionally wrapped in ZIP archives).

Member Function Documentation

◆ FromXmlString< T >()

static T NanoByte.Common.Storage.XmlStorage.FromXmlString< T > ( [Localizable(false)] string  data)
inlinestatic

Loads an object from an XML string.

Template Parameters
TThe type of object the XML string shall be converted into.
Parameters
dataThe XML string to be parsed.
Returns
The loaded object.
Exceptions
InvalidDataExceptionA problem occurred while deserializing the XML data.

◆ LoadXml< T >() [1/2]

static T NanoByte.Common.Storage.XmlStorage.LoadXml< T > ( [Localizable(false)] string  path)
inlinestatic

Loads an object from an XML file.

Template Parameters
TThe type of object the XML stream shall be converted into.
Parameters
pathThe path of the file to load.
Returns
The loaded object.
Exceptions
IOExceptionA problem occurred while reading the file.
UnauthorizedAccessExceptionRead access to the file is not permitted.
InvalidDataExceptionA problem occurred while deserializing the XML data.

Uses AtomicRead internally.

◆ LoadXml< T >() [2/2]

static T NanoByte.Common.Storage.XmlStorage.LoadXml< T > ( Stream  stream)
inlinestatic

Loads an object from an XML file.

Template Parameters
TThe type of object the XML stream shall be converted into.
Parameters
streamThe stream to read the encoded XML data from.
Returns
The loaded object.
Exceptions
InvalidDataExceptionA problem occurred while deserializing the XML data.

◆ SaveXml< T >() [1/2]

static void NanoByte.Common.Storage.XmlStorage.SaveXml< T > ( this T  data,
[Localizable(false)] string  path,
[Localizable(false)] string?  stylesheet = null 
)
inlinestatic

Saves an object in an XML file ending with a line break.

This method performs an atomic write operation when possible.

Template Parameters
TThe type of object to be saved in an XML stream.
Parameters
dataThe object to be stored.
pathThe path of the file to write.
stylesheetThe path of an XSL stylesheet for T ; can be null.
Exceptions
IOExceptionA problem occurred while writing the file.
UnauthorizedAccessExceptionWrite access to the file is not permitted.

Uses

See also
AtomicWrite

internally.

◆ SaveXml< T >() [2/2]

static void NanoByte.Common.Storage.XmlStorage.SaveXml< T > ( this T  data,
Stream  stream,
[Localizable(false)] string?  stylesheet = null 
)
inlinestatic

Saves an object in an XML stream ending with a line break.

Template Parameters
TThe type of object to be saved in an XML stream.
Parameters
dataThe object to be stored.
streamThe stream to write the encoded XML data to.
stylesheetThe path of an XSL stylesheet for T ; can be null.

◆ ToXmlString< T >()

static string NanoByte.Common.Storage.XmlStorage.ToXmlString< T > ( this T  data,
[Localizable(false)] string?  stylesheet = null 
)
inlinestatic

Returns an object as an XML string ending with a line break.

Template Parameters
TThe type of object to be saved in an XML string.
Parameters
dataThe object to be stored.
stylesheetThe path of an XSL stylesheet for T ; can be null.
Returns
A string containing the XML code.

Member Data Documentation

◆ XsiNamespace

const string NanoByte.Common.Storage.XmlStorage.XsiNamespace = "http://www.w3.org/2001/XMLSchema-instance"
static

The XML namespace used for XML Schema instance.


The documentation for this class was generated from the following file: