Add warning

This commit is contained in:
Игорь Гордеев 2023-12-27 19:43:17 +04:00
parent 9b337df21c
commit 4f67d6f78a
3 changed files with 14 additions and 21 deletions

View File

@ -3,15 +3,6 @@ using ElectricLocomotive.Generics;
using Microsoft.Extensions.Logging;
using ProjectElectricLocomotive;
using ProjectElectricLocomotive.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ElectricLocomotive
{
@ -113,11 +104,11 @@ namespace ElectricLocomotive
MessageBox.Show("Объект добавлен");
CollectionPictureBox.Image = obj.ShowLocomotives();
_logger.LogInformation($"Добавлен объект {obj}");
;
}
else
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogInformation("Не удалось добавить объект");
}
}
catch (StorageOverflowException ex)
@ -154,13 +145,13 @@ namespace ElectricLocomotive
else
{
MessageBox.Show("Не удалось удалить объект");
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
_logger.LogWarning($"Не найден объект по позиции: {pos}");
}
}
catch (LocoNotFoundException ex)
{
MessageBox.Show(ex.Message);
_logger.LogWarning($"Не найден объект по позиции: {obj}");
_logger.LogWarning($"Не найден объект по позиции: {pos}");
}
}

View File

@ -27,13 +27,13 @@ namespace ElectricLocomotive.Generics
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static int operator +(LocomotivesGenericCollection<T, U> collect, T? loco)
public static int operator +(LocomotivesGenericCollection<T?, U?> collect, T? locomotive)
{
if (loco == null)
if (locomotive == null)
{
return -1;
}
return collect._collection.Insert(loco);
return collect._collection.Insert(locomotive);
}

View File

@ -36,14 +36,16 @@ namespace ProjectElectricLocomotive.Generics
_places.Insert(position, loco);
return position;
}
public bool Remove(int position)
{
if (position < 0 || position >= _places.Count)
public T? Remove(int position)
{
if (position >= Count || position < 0)
return null;
T? tmp = _places[position];
if (tmp == null)
throw new LocoNotFoundException(position);
}
_places.RemoveAt(position);
return true;
_places[position] = null;
return tmp;
}
public T? this[int position]
{