public override long GetSize(FieldInfo field, object obj) { object[] array = ((IEnumerable)obj).Cast <object>().ToArray(); long size = ReadableData.GetObjectSize(CountType, 0); foreach (object o in array) { size += ReadableData.GetObjectSize(Type, o); } return(size); }
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) { MethodInfo method = typeof(OWLib.Extensions).GetMethod("Read").MakeGenericMethod(type); return(method.Invoke(reader, new object[] { reader })); } throw new NotImplementedException(); }
public override long GetSize(FieldInfo field, object obj) { return(ReadableData.GetObjectSize(obj.GetType(), obj)); }
public override long GetNoDataStartSize(FieldInfo field, object obj) { return(ReadableData.GetObjectSize(CountType, 0)); }