Example #1
0
        public static void Write(this BinaryWriter writer, IList value, BinaryUtility.TypeCodes elementTypeCode)
        {
            if (elementTypeCode == BinaryUtility.TypeCodes.Other || BinaryUtility.IsGenericTypeCode(elementTypeCode))
            {
                writer.Write(value.GetType().GetGenericArguments()[0]);
            }

            if (elementTypeCode == BinaryUtility.TypeCodes.Other || BinaryUtility.IsReferenceTypeCode(elementTypeCode))
            {
                writer.Write(value.Count);

                for (int i = 0; i < value.Count; i++)
                {
                    writer.Write(value[i]);
                }
            }
            else
            {
                writer.Write(value.Count);

                for (int i = 0; i < value.Count; i++)
                {
                    writer.Write(value[i], elementTypeCode);
                }
            }
        }
Example #2
0
        public static void Write(this BinaryWriter writer, IList value)
        {
            var elementTypeCode = BinaryUtility.ToTypeCode(value.GetType().GetGenericArguments()[0]);

            writer.Write((byte)elementTypeCode);
            writer.Write(value, elementTypeCode);
        }
Example #3
0
        public static void Write(this BinaryWriter writer, Array value, BinaryUtility.TypeCodes elementTypeCode)
        {
            if (elementTypeCode == BinaryUtility.TypeCodes.Other || BinaryUtility.IsGenericTypeCode(elementTypeCode))
            {
                writer.Write(value.GetType().GetElementType());
            }

            if (BinaryUtility.IsReferenceTypeCode(elementTypeCode))
            {
                writer.Write(value.Length);

                for (int i = 0; i < value.Length; i++)
                {
                    writer.Write(value.GetValue(i));
                }
            }
            else
            {
                writer.Write(value.Length);

                for (int i = 0; i < value.Length; i++)
                {
                    writer.Write(value.GetValue(i), elementTypeCode);
                }
            }
        }
Example #4
0
        public static void Write(this BinaryWriter writer, Array value)
        {
            var typeCode = BinaryUtility.ToTypeCode(value.GetType().GetElementType());

            writer.Write((byte)typeCode);
            writer.Write(value, typeCode);
        }
Example #5
0
        public static void Write(this BinaryWriter writer, object value)
        {
            var typeCode = BinaryUtility.ToTypeCode(value);

            writer.Write((byte)typeCode);
            writer.Write(value, typeCode);
        }
Example #6
0
        static IList ReadObjectList(this BinaryReader reader, BinaryUtility.TypeCodes elementTypeCode)
        {
            Type elementType = BinaryUtility.ToType(elementTypeCode) ?? reader.ReadType();
            int  count       = reader.ReadInt32();
            var  list        = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType), count);

            for (int i = 0; i < count; i++)
            {
                list.Add(reader.ReadObject());
            }

            return(list);
        }
Example #7
0
        static Array ReadObjectArray(this BinaryReader reader, BinaryUtility.TypeCodes elementTypeCode)
        {
            Type elementType = BinaryUtility.ToType(elementTypeCode) ?? reader.ReadType();
            int  length      = reader.ReadInt32();
            var  array       = Array.CreateInstance(elementType, length);

            for (int i = 0; i < length; i++)
            {
                array.SetValue(reader.ReadObject(), i);
            }

            return(array);
        }
Example #8
0
        static object ReadOther(this BinaryReader reader)
        {
            ushort serializerId = reader.ReadUInt16();
            var    serializer   = BinaryUtility.GetSerializer(BinaryUtility.ToType());

            if (serializer == null)
            {
                return(null);
            }
            else
            {
                return(serializer.Deserialize(reader));
            }
        }
Example #9
0
        static void WriteOther(this BinaryWriter writer, object value)
        {
            var serializer = BinaryUtility.GetSerializer(value.GetType());

            if (serializer == null)
            {
                writer.Write(ushort.MaxValue - 1);
            }
            else
            {
                writer.Write(serializer.TypeIdentifier);
                serializer.Serialize(writer, value);
            }
        }