private void DisplayXmlIfSelected(IXmlSerializable exception) { if (tabsView.SelectedIndex != 2 || _xmlWritten) { return; } if (exception == null) { rtfXml.Text = string.Empty; } else { using (var stringWriter = new StringWriter()) { XmlTextWriter writer = new XmlRichTextWriter(stringWriter) { Formatting = Formatting.Indented, Indentation = 2 }; exception.WriteOuterXml(writer); writer.Close(); rtfXml.Rtf = stringWriter.ToString(); } } _xmlWritten = true; }
public static void Serialize(object source, XmlWriter writer) { const string method = "Serialize"; if (source == null) { throw new Exceptions.NullParameterException(typeof(XmlSerializer), method, "source"); } if (writer == null) { throw new Exceptions.NullParameterException(typeof(XmlSerializer), method, "writer"); } // Look for IXmlSerializable first. if (source is IXmlSerializable) { // Let it do it. IXmlSerializable xmlSerializable = source as IXmlSerializable; xmlSerializable.WriteOuterXml(writer); } else { // Fall back to the system serializer. System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(source.GetType()); xmlSerializer.Serialize(writer, source); } }
private bool WriteLinkMeXmlParameter(XmlWriteAdaptor adaptor) { // Ask the object to serialize itself using the IXmlSerializable interface. IXmlSerializable serializable = m_value as IXmlSerializable; if (serializable == null) { return(false); } WriteValueInfo(adaptor, new ClassInfo(m_value.GetType()), ValueFormat.LinkMeXml); serializable.WriteOuterXml(adaptor.XmlWriter); return(true); }
public static string Serialize(IXmlSerializable source) { const string method = "Serialize"; if (source == null) { throw new Exceptions.NullParameterException(typeof(XmlSerializer), method, "source"); } // Create a writer for the output. StringBuilder builder = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(builder)); source.WriteOuterXml(writer); return(builder.ToString()); }