示例#1
0
        /// <summary>
        /// Applies a protocol-buffer from an XmlReader to an existing instance.
        /// </summary>
        /// <typeparam name="T">The type being merged.</typeparam>
        /// <param name="instance">The existing instance to be modified (cannot be null).</param>
        /// <param name="reader">The XmlReader containing the data to apply to the instance (cannot be null).</param>
        public static void Merge <T>(System.Xml.XmlReader reader, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            const int LEN = 4096;

            byte[] buffer = new byte[LEN];
            using (MemoryStream ms = new MemoryStream())
            {
                int depth = reader.Depth;
                while (reader.Read() && reader.Depth > depth)
                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Text)
                    {
                        int read;
                        while ((read = reader.ReadContentAsBase64(buffer, 0, LEN)) > 0)
                        {
                            ms.Write(buffer, 0, read);
                        }
                        if (reader.Depth <= depth)
                        {
                            break;
                        }
                    }
                }
                ms.Position = 0;
                Serializer.Merge(ms, instance);
            }
        }
示例#2
0
 void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
 {
     Serializer.Merge(reader, this);
 }
示例#3
0
 protected DatabaseCompatRem(SerializationInfo info, StreamingContext context)
     : this()
 {
     Serializer.Merge <DatabaseCompatRem>(info, this);
 }