class ExtentionBoat
This commit is contained in:
parent
01ea98b1c7
commit
845a719d29
62
Boats/Boats/ExtentionBoat.cs
Normal file
62
Boats/Boats/ExtentionBoat.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Boats
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Расширение для класса DrawingBoat
|
||||||
|
/// </summary>
|
||||||
|
internal static class ExtentionBoat
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DrawingBoat CreateDraingBoat(this string info)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(_separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingBoat(
|
||||||
|
Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawingCatamaran(
|
||||||
|
Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawingBoat"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetDataForSave(this DrawingBoat drawingBoat)
|
||||||
|
{
|
||||||
|
var car = drawingBoat.Boat;
|
||||||
|
var str = $"{car.Speed}{_separatorForObject}{car.Weight}{_separatorForObject}{car.BodyColor.Name}";
|
||||||
|
if (car is not EntityCatamaran catamaran)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return $"{str}{_separatorForObject}{catamaran.DopColor.Name}{_separatorForObject}{catamaran.Bobbers}{_separatorForObject}{catamaran.Sail}";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user