using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DoubleDeckerbus.Entities; namespace DoubleDeckerbus.Drawing { public static class ExtentionDrawingBus { public static DrawingBus? CreateDrawingBus(this string info, char separatorForObject, int width, int height) { string[] strs = info.Split(separatorForObject); if (strs.Length == 3) { return new DrawingBus( Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); } if (strs.Length == 6) { return new DrawingDoubleDeckerbus( Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]), width, height); } return null; } public static string GetDataForSave(this DrawingBus DrawingBus, char separatorForObject) { var truck = DrawingBus.EntityBus; if (truck == null) { return string.Empty; } var str = $"{truck.Speed}{separatorForObject}{truck.Weight}{separatorForObject}{truck.BodyColor.Name}"; if (truck is not EntityDoubleDeckerbus DoubleDeckerBus) { return str; } return $"{str}{separatorForObject}{DoubleDeckerBus.AddColor.Name}{separatorForObject}{DoubleDeckerBus.IsSecondFloor}{separatorForObject}{DoubleDeckerBus.IsStairs}"; } } }