public override BinaryCarsFile Deserialize(Stream serializationStream) { serializationStream.ThrowArgumentNullExceptionIfNull(); BinaryReader reader = new BinaryReader(serializationStream); BinaryCarsFile file = new BinaryCarsFile(); CarsCollection <BinaryCar> cars = new CarsCollection <BinaryCar>(); int headerRawSize = Marshal.SizeOf(typeof(short)); int recordsCountRawSize = Marshal.SizeOf(typeof(uint)); int carRawSize = Marshal.SizeOf(typeof(BinaryCar)); byte[] headerRawData = new byte[headerRawSize]; reader.Read(headerRawData, 0, headerRawSize); file.headerField = (short)RawDeserialize(typeof(short), ref headerRawData); byte[] recordsCountRawData = new byte[recordsCountRawSize]; reader.Read(recordsCountRawData, 0, recordsCountRawSize); file.RecordsCount = (uint)RawDeserialize(typeof(uint), ref recordsCountRawData); while (reader.PeekChar() > -1) { byte[] carRawData = new byte[carRawSize]; reader.Read(carRawData, 0, carRawSize); BinaryCar car = (BinaryCar)RawDeserialize(typeof(BinaryCar), ref carRawData); cars.Add(car); } file.Cars = cars; return(file); }
public static CarsCollection <T> CreateCarsCollection <T>() where T : XmlCar, new() { CarsCollection <T> cars = new CarsCollection <T>(); for (uint i = 0; i < TestContext.CurrentContext.Random.NextByte(1, byte.MaxValue); i++) { var car = CreateCar <T>(); if (!cars.Contains(car.BrandName)) { cars.Add(car); } } return(cars); }