public void ReadObjects(string fileName) { MappedObjectData.Clear(); MappedObjects.Clear(); for (var i = 0; i < Count; i++) { var dataBytes = new byte[DataLength]; var objectOffset = Offset + (i * Size); using (var fs = File.OpenRead(fileName)) { fs.Seek(objectOffset, SeekOrigin.Begin); fs.Read(dataBytes, 0, DataLength); } Type type = typeof(T); var ctor = type.GetConstructor(new[] { typeof(byte[]), typeof(long) }); var mappedObject = (T)ctor.Invoke(new object[] { dataBytes, objectOffset }); if (mappedObject.Id == -1) { mappedObject.Id = i; } if (MappedObjectData.ContainsKey(mappedObject.Id)) { MappedObjectData[mappedObject.Id].AddOffset(objectOffset, dataBytes); } else { MappedObjectData.Add(mappedObject.Id, mappedObject); MappedObjects.Add(mappedObject); } } }
public void AddMappedObject(T mappedObject) { MappedObjectData.Add(mappedObject.Id, mappedObject); MappedObjects.Add(mappedObject); }