Esempio n. 1
0
            public override long GetSize(FieldInfo field, object obj)
            {
                object[] array = ((IEnumerable)obj).Cast <object>().ToArray();
                long     size  = 0;

                foreach (object o in array)
                {
                    size += ReadableData.GetObjectSize(Type, o);
                }

                return(size);
            }
Esempio n. 2
0
        public static object ReadType(Type type, BinaryReader reader)
        {
            bool isStruct = type.IsValueType && !type.IsPrimitive;

            if (type == typeof(byte))
            {
                return(reader.ReadByte());
            }
            if (type == typeof(uint))
            {
                return(reader.ReadUInt32());
            }
            if (type == typeof(int))
            {
                return(reader.ReadInt32());
            }
            if (type == typeof(float))
            {
                return(reader.ReadSingle());
            }
            if (type == typeof(ulong))
            {
                return(reader.ReadUInt64());
            }

            if (type.IsEnum)
            {
                return(ReadType(type.GetEnumUnderlyingType(), reader));
            }

            if (type.IsSubclassOf(typeof(ReadableData)))
            {
                ReadableData inst = (ReadableData)Activator.CreateInstance(type);
                inst.Read(reader);
                return(inst);
            }

            if (isStruct)
            {
                // ReSharper disable once PossibleNullReferenceException
                MethodInfo method = typeof(Extensions).GetMethod(nameof(Extensions.Read)).MakeGenericMethod(type);
                return(method.Invoke(reader, new object[] { reader }));
            }

            throw new NotImplementedException();
        }
Esempio n. 3
0
 public override long GetSize(FieldInfo field, object obj)
 {
     return(ReadableData.GetObjectSize(obj.GetType(), obj));
 }
Esempio n. 4
0
 public override long GetNoDataStartSize(FieldInfo field, object obj)
 {
     return(ReadableData.GetObjectSize(CountType, 0));
 }