static void Main(string[] args) { var sedan = new Sedan(1); var hatchback = new Hatchback(2); var teslaHQ = new TeslaHq(); teslaHQ.Attach(sedan); teslaHQ.Attach(hatchback); //2.0.0 teslaHQ.MajorUpgrade(); teslaHQ.NotifySoftwareUpdate(); teslaHQ.Detach(hatchback); //2.0.1 teslaHQ.PatchUpdate(); teslaHQ.NotifySoftwareUpdate(); System.Console.WriteLine(sedan.SoftwareVersion); System.Console.WriteLine(hatchback.SoftwareVersion); var cars = new CarsCollection(); cars.AddCar(sedan); cars.AddCar(hatchback); foreach (var car in cars) { System.Console.WriteLine(car.ToString()); } }
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); }