コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 public void Serialize(CustomXmlWriter writer, object o)
 {
     AddCDataProperties(writer);
     base.Serialize(writer, o);
 }