Beispiel #1
0
        object ReadList()
        {
            object ret = ReadObject();

            //Type t = ret.GetType().GetInterfaces().Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList<>)).First();
            Type t = ret.GetType();
            DynamicMethodDelegate dmd = DynamicMethodDelegateFactory.CreateDelegate(t.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public, null, t.GetGenericArguments(), null));

            TypeMarker elemt = (TypeMarker)reader.ReadByte();
            int        len   = (int)ReadVInt();

            if (TypeMarkerUtil.IsFinal(elemt))
            {
                for (int i = 0; i < len; i++)
                {
                    dmd(ret, new[] { ReadValue(elemt) });
                }
            }
            else
            {
                for (int i = 0; i < len; i++)
                {
                    dmd(ret, new[] { ReadValue() });
                }
            }
            return(ret);
        }
Beispiel #2
0
        void WriteArray(ArrayStruct array)
        {
            TypeStruct ts = types.GetValue(array.ElementType);

            writer.Write((byte)array.NativeElementType);
            WriteVInt(array.ElementType);
            WriteVInt((uint)array.Values.Length);
            bool b = !TypeMarkerUtil.IsFinal(array.NativeElementType);

            foreach (var x in array.Values)
            {
                WriteValue(x, b);
            }
        }
Beispiel #3
0
        void WriteList(ListStruct list)
        {
            bool b = !TypeMarkerUtil.IsFinal(list.ElementType);

            WriteVInt(list.Type);
            foreach (var m in list.MemberValues)
            {
                WriteValue(m);
            }
            writer.Write((byte)list.ElementType);
            WriteVInt((uint)list.Values.Length);
            foreach (var m in list.Values)
            {
                WriteValue(m, b);
            }
        }
Beispiel #4
0
        Array ReadArray()
        {
            TypeMarker elemt = (TypeMarker)reader.ReadByte();
            Type       t     = types[(int)ReadVInt()];
            Array      arr   = Array.CreateInstance(t, (int)ReadVInt());

            if (TypeMarkerUtil.IsFinal(elemt))
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    arr.SetValue(ReadValue(elemt), i);
                }
            }
            else
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    arr.SetValue(ReadValue(), i);
                }
            }
            return(arr);
        }