Example #1
0
        public void Serialize <T1, T2, T3, T4, T5>(MethodInfo info, BitStream stream, ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4, ref T5 arg5)
        {
            var s1 = MyFactory.GetSerializer <T1>();
            var s2 = MyFactory.GetSerializer <T2>();
            var s3 = MyFactory.GetSerializer <T3>();
            var s4 = MyFactory.GetSerializer <T4>();
            var s5 = MyFactory.GetSerializer <T5>();

            var args  = info.GetParameters();
            var info1 = MySerializeInfo.CreateForParameter(args, 0);
            var info2 = MySerializeInfo.CreateForParameter(args, 1);
            var info3 = MySerializeInfo.CreateForParameter(args, 2);
            var info4 = MySerializeInfo.CreateForParameter(args, 3);
            var info5 = MySerializeInfo.CreateForParameter(args, 4);

            if (stream.Reading)
            {
                MySerializationHelpers.CreateAndRead(stream, out arg1, s1, info1);
                MySerializationHelpers.CreateAndRead(stream, out arg2, s2, info2);
                MySerializationHelpers.CreateAndRead(stream, out arg3, s3, info3);
                MySerializationHelpers.CreateAndRead(stream, out arg4, s4, info4);
                MySerializationHelpers.CreateAndRead(stream, out arg5, s5, info5);
            }
            else
            {
                MySerializationHelpers.Write(stream, ref arg1, s1, info1);
                MySerializationHelpers.Write(stream, ref arg2, s2, info2);
                MySerializationHelpers.Write(stream, ref arg3, s3, info3);
                MySerializationHelpers.Write(stream, ref arg4, s4, info4);
                MySerializationHelpers.Write(stream, ref arg5, s5, info5);
            }
        }
Example #2
0
        /// <summary>
        /// Extracts method arguments from the bitstream or packs them back in, depending on stream read mode.
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="info"></param>
        /// <param name="stream"></param>
        /// <param name="arg1"></param>
        public void Serialize <T1>(MethodInfo info, BitStream stream, ref T1 arg1)
        {
            var s1 = MyFactory.GetSerializer <T1>();

            var args  = info.GetParameters();
            var info1 = MySerializeInfo.CreateForParameter(args, 0);

            if (stream.Reading)
            {
                MySerializationHelpers.CreateAndRead(stream, out arg1, s1, info1);
            }
            else
            {
                MySerializationHelpers.Write(stream, ref arg1, s1, info1);
            }
        }
Example #3
0
        SerializeDelegate <T1, T2, T3, T4, T5, T6, T7> CreateSerializer <T1, T2, T3, T4, T5, T6, T7>(MethodInfo info)
        {
            // TODO: Use method info to get parameter attributes and create MySerializeInfo from them

            var s2 = MyFactory.GetSerializer <T2>();
            var s3 = MyFactory.GetSerializer <T3>();
            var s4 = MyFactory.GetSerializer <T4>();
            var s5 = MyFactory.GetSerializer <T5>();
            var s6 = MyFactory.GetSerializer <T6>();
            var s7 = MyFactory.GetSerializer <T7>();

            var args  = info.GetParameters();
            var info2 = MySerializeInfo.CreateForParameter(args, 0);
            var info3 = MySerializeInfo.CreateForParameter(args, 1);
            var info4 = MySerializeInfo.CreateForParameter(args, 2);
            var info5 = MySerializeInfo.CreateForParameter(args, 3);
            var info6 = MySerializeInfo.CreateForParameter(args, 4);
            var info7 = MySerializeInfo.CreateForParameter(args, 5);

            return(delegate(T1 inst, BitStream stream, ref T2 arg2, ref T3 arg3, ref T4 arg4, ref T5 arg5, ref T6 arg6, ref T7 arg7)
            {
                if (stream.Reading)
                {
                    MySerializationHelpers.CreateAndRead(stream, out arg2, s2, info2);
                    MySerializationHelpers.CreateAndRead(stream, out arg3, s3, info3);
                    MySerializationHelpers.CreateAndRead(stream, out arg4, s4, info4);
                    MySerializationHelpers.CreateAndRead(stream, out arg5, s5, info5);
                    MySerializationHelpers.CreateAndRead(stream, out arg6, s6, info6);
                    MySerializationHelpers.CreateAndRead(stream, out arg7, s7, info7);
                }
                else
                {
                    MySerializationHelpers.Write(stream, ref arg2, s2, info2);
                    MySerializationHelpers.Write(stream, ref arg3, s3, info3);
                    MySerializationHelpers.Write(stream, ref arg4, s4, info4);
                    MySerializationHelpers.Write(stream, ref arg5, s5, info5);
                    MySerializationHelpers.Write(stream, ref arg6, s6, info6);
                    MySerializationHelpers.Write(stream, ref arg7, s7, info7);
                }
            });
        }