private void AddCDataProperties(CustomXmlWriter writer) { var attributes = _type.GetCustomAttributes(typeof(CDataAttribute), true).Cast <CDataAttribute>(); foreach (var attribute in attributes) { var path = new List <string> { _type.Name }; path.AddRange(attribute.Property.Split('.')); if (attribute.PropertyType != typeof(string)) { foreach (var property in attribute.PropertyType.GetProperties() .Where(p => p.PropertyType == typeof(string)) .Select(p => p.Name)) { writer.AddCDataPath(path.Append(property)); } } else { writer.AddCDataPath(path); } } }
public static void SerializeXmlToStream<T>(T subject, Stream stream) { using var sw = new StreamWriter(stream, Encoding.UTF8); using var xw = new CustomXmlWriter(XmlWriter.Create(sw, WriterSettings)); new CustomXmlSerializer(typeof(T)).Serialize(xw, subject); }
public static string SerializeXml<T>(T subject) { using var sw = new Utf8StringWriter(); using var xw = new CustomXmlWriter(XmlWriter.Create(sw, WriterSettings)); new CustomXmlSerializer(typeof(T)).Serialize(xw, subject); return sw.ToString(); }
public void Serialize(CustomXmlWriter writer, object o) { AddCDataProperties(writer); base.Serialize(writer, o); }