PIbd22_Kamcharova_K.A._Doub.../DoubleDeckerBus/Drawing/ExtentionDrawingBus.cs

50 lines
1.7 KiB
C#
Raw Permalink Normal View History

2023-12-15 20:07:22 +04:00
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}";
}
}
}