/// <summary> /// Initializes a new instance of the <see cref="XmlSerializationContextInfo"/> class. /// </summary> /// <param name="xmlContent">Content of the XML.</param> /// <param name="model">The model.</param> /// <exception cref="ArgumentNullException">The <paramref name="xmlContent" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="model" /> is <c>null</c>.</exception> public XmlSerializationContextInfo(string xmlContent, ModelBase model) { Argument.IsNotNull("xmlContent", xmlContent); Argument.IsNotNull("model", model); Initialize(xmlContent, model); }
//private DataContractSerializer _dataContractSerializer; #region Constructors /// <summary> /// Initializes a new instance of the <see cref="XmlSerializationContextInfo" /> class. /// </summary> /// <param name="element">The element.</param> /// <param name="model">The model.</param> /// <exception cref="ArgumentNullException">The <paramref name="element" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="model" /> is <c>null</c>.</exception> public XmlSerializationContextInfo(XElement element, ModelBase model) { Argument.IsNotNull("element", element); Argument.IsNotNull("model", model); Initialize(element, model); }
/// <summary> /// Initializes a new instance of the <see cref="ModelBase.BackupData"/> class. /// </summary> /// <param name="obj">Object to backup.</param> public BackupData(ModelBase obj) { Argument.IsNotNull("obj", obj); _object = obj; CreateBackup(); }
//private DataContractSerializer _dataContractSerializer; #region Constructors /// <summary> /// Initializes a new instance of the <see cref="XmlSerializationContextInfo" /> class. /// </summary> /// <param name="element">The element.</param> /// <param name="model">The model.</param> /// <exception cref="ArgumentNullException">The <paramref name="element" /> is <c>null</c>.</exception> public XmlSerializationContextInfo(XElement element, ModelBase model) { Argument.IsNotNull("element", element); Argument.IsNotNull("model", model); Element = element; Model = model; }
/// <summary> /// Initializes a new instance of the <see cref="XmlSerializationContextInfo" /> class. /// </summary> /// <param name="xmlReader">The XML reader.</param> /// <param name="model">The model.</param> /// <exception cref="ArgumentNullException">The <paramref name="xmlReader" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="model" /> is <c>null</c>.</exception> public XmlSerializationContextInfo(XmlReader xmlReader, ModelBase model) { Argument.IsNotNull("xmlReader", xmlReader); Argument.IsNotNull("model", model); var modelType = model.GetType(); var elementStart = string.Format("<{0}", modelType.Name); if (xmlReader.HasAttributes) { for (int i = 0; i < xmlReader.AttributeCount; i++) { xmlReader.MoveToAttribute(i); var attributeName = xmlReader.LocalName; var attributeValue = xmlReader.Value; elementStart += string.Format(" {0}=\"{1}\"", attributeName, attributeValue); } xmlReader.MoveToElement(); } elementStart += ">"; xmlReader.MoveToContent(); var xmlContent = xmlReader.ReadInnerXml(); if (xmlContent.StartsWith("<")) { #if SL5 xmlContent = System.Windows.Browser.HttpUtility.HtmlDecode(xmlContent); #else xmlContent = System.Net.WebUtility.HtmlDecode(xmlContent); #endif } var elementEnd = string.Format("</{0}>", modelType.Name); var finalXmlContent = string.Format("{0}{1}{2}", elementStart, xmlContent, elementEnd); Initialize(finalXmlContent, model); }
/// <summary> /// Initializes a new instance of the <see cref="XmlSerializationContextInfo" /> class. /// </summary> /// <param name="xmlReader">The XML reader.</param> /// <param name="model">The model.</param> /// <exception cref="ArgumentNullException">The <paramref name="xmlReader" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="model" /> is <c>null</c>.</exception> public XmlSerializationContextInfo(XmlReader xmlReader, ModelBase model) { Argument.IsNotNull("xmlReader", xmlReader); Argument.IsNotNull("model", model); xmlReader.MoveToContent(); var xmlContent = xmlReader.ReadInnerXml(); if (xmlContent.StartsWith("<")) { #if SL5 xmlContent = System.Windows.Browser.HttpUtility.HtmlDecode(xmlContent); #else xmlContent = System.Net.WebUtility.HtmlDecode(xmlContent); #endif } var modelType = model.GetType(); var elementStart = string.Format("<{0}>", modelType.Name); var elementEnd = string.Format("</{0}>", modelType.Name); var finalXmlContent = string.Format("{0}{1}{2}", elementStart, xmlContent, elementEnd); Initialize(finalXmlContent, model); }
/// <summary> /// Saves the specified model to the file as xml. /// </summary> /// <param name="model">The model.</param> /// <param name="filePath">The file path.</param> public static void SaveAsXml(this ModelBase model, string filePath) { Save(model, filePath, SerializationFactory.GetXmlSerializer()); }
/// <summary> /// Saves as XML. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The stream.</param> public static void SaveAsXml(this ModelBase model, Stream stream) { Save(model, stream, SerializationFactory.GetXmlSerializer()); }
private void Initialize(XElement element, ModelBase model) { Element = element; Model = model; }
private void Initialize(string xmlContent, ModelBase model) { Initialize(XElement.Parse(xmlContent), model); }