Пример #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 <[DynamicallyAccessedMembers(DynamicAccess.ContractType)] T>(System.Xml.XmlReader reader, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (reader is null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (instance is null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
            const int LEN = 4096;

            byte[] buffer = new byte[LEN];
            int    read;

            using MemoryStream ms = new MemoryStream();
            int depth = reader.Depth;

            while (reader.Read() && reader.Depth > depth)
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                {
                    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
        /// <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));
            }
#pragma warning disable RCS1165 // Unconstrained type parameter checked for null.
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
#pragma warning restore RCS1165 // Unconstrained type parameter checked for null.

            const int LEN    = 4096;
            byte[]    buffer = new byte[LEN];
            int       read;
            using MemoryStream ms = new MemoryStream();
            int depth = reader.Depth;
            while (reader.Read() && reader.Depth > depth)
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                {
                    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);
        }
Пример #3
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("reader");
            }

            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }



            const int LEN = 4096;

            byte[] buffer = new byte[LEN];

            int read;

            using (MemoryStream ms = new MemoryStream())

            {
                int depth = reader.Depth;

                while (reader.Read() && reader.Depth > depth)

                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Text)

                    {
                        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);
            }
        }
Пример #4
0
        public static void Merge <T>(XmlReader reader, T instance)
            where T : IXmlSerializable
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            byte[] numArray = new byte[4096];
            using (MemoryStream memoryStream = new MemoryStream())
            {
                int depth = reader.Depth;
                do
                {
Label1:
                    if (!reader.Read() || reader.Depth <= depth)
                    {
                        break;
                    }
                    if (reader.NodeType == XmlNodeType.Text)
                    {
                        while (true)
                        {
                            int num  = reader.ReadContentAsBase64(numArray, 0, 4096);
                            int num1 = num;
                            if (num <= 0)
                            {
                                goto Label0;
                            }
                            memoryStream.Write(numArray, 0, num1);
                        }
                    }
                    else
                    {
                        goto Label1;
                    }
Label0:
                }while (reader.Depth > depth);
                memoryStream.Position = (long)0;
                Serializer.Merge <T>(memoryStream, instance);
            }
        }
Пример #5
0
        internal static TValueActual CheckSubType <TValueActual>(T instance)
            where TValueActual : class, T
        {
            TValueActual actual = instance as TValueActual;

            if (actual == null && instance != null)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    Serializer.Serialize <T>(ms, instance);
                    actual = ObjectFactory <TValueActual> .Create();

                    // (note - don't use ObjectCreation callback here - Merge will own the callbacks)
                    ms.Position = 0;
                    Serializer.Merge <T>(ms, actual);
                }
            }
            return(actual);
        }
Пример #6
0
 void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
 {
     Serializer.Merge(reader, this);
 }
Пример #7
0
 protected DatabaseCompatRem(SerializationInfo info, StreamingContext context)
     : this()
 {
     Serializer.Merge <DatabaseCompatRem>(info, this);
 }
Пример #8
0
 public static void Merge <T>(SerializationInfo info, T instance)
     where T : class, ISerializable
 {
     Serializer.Merge <T>(info, new StreamingContext(StreamingContextStates.Persistence), instance);
 }
Пример #9
0
 public static void DecodeProtoMsg <T>(this SmartBuffer buff, T msg)
 {
     Serializer.Merge(buff, msg);
 }
Пример #10
0
 public static object DecodeProtoMsg(this SmartBuffer buff, byte[] bytes, object msg, Type type)
 {
     buff.Reset();
     buff.In(bytes, 0, (uint)bytes.Length);
     return(Serializer.Merge(buff, msg, type));
 }
Пример #11
0
 public static object DecodeProtoMsg(this SmartBuffer buff, object msg, Type type)
 {
     return(Serializer.Merge(buff, msg, type));
 }
Пример #12
0
 public static void DecodeProtoMsg <T>(this SmartBuffer buff, byte[] bytes, T msg)
 {
     buff.Reset();
     buff.In(bytes, 0, (uint)bytes.Length);
     Serializer.Merge(buff, msg);
 }