From adbf4e37f0c494343e7567621fae1daa270fc9a4 Mon Sep 17 00:00:00 2001 From: Geo7312 Date: Fri, 7 Jun 2024 22:42:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=208=20(=D0=B4=D0=BE?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionGenericObjects/ICollectionGenericObjects.cs | 4 ++-- .../CollectionGenericObjects/ListGenericObjects.cs | 8 ++++---- .../CollectionGenericObjects/MassiveGenericObjects.cs | 8 ++++---- .../Exceptions/CollectionAlreadyExistsException.cs | 2 +- .../ProjectTrolleybus/FormTrolleyBCollection.cs | 5 +++++ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ICollectionGenericObjects.cs index c51216f..a5db1aa 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -23,14 +23,14 @@ public interface ICollectionGenericObjects /// /// /// - int Insert(T obj, IEqualityComparer? comparer = null); + int Insert(T obj, IEqualityComparer? comparer = null); /// /// Добавление объекта в коллекцию /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj, int position, IEqualityComparer? comparer = null); + int Insert(T obj, int position, IEqualityComparer? comparer = null); /// /// Удаление объекта из коллекции с конкретной позиции diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ListGenericObjects.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ListGenericObjects.cs index ade2479..1445077 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ListGenericObjects.cs @@ -44,10 +44,10 @@ public class ListGenericObjects : ICollectionGenericObjects } - public int Insert(T obj, IEqualityComparer? comparer = null) + public int Insert(T obj, IEqualityComparer? comparer = null) { // TODO выброс ошибки, если такой объект есть в коллекции - if (comparer != null && _collection.Contains(obj)) + if (comparer != null && _collection.Contains(obj, comparer)) { throw new CollectionAlreadyExistsException(); } @@ -62,10 +62,10 @@ public class ListGenericObjects : ICollectionGenericObjects } - public int Insert(T obj, int position, IEqualityComparer? comparer = null) + public int Insert(T obj, int position, IEqualityComparer? comparer = null) { // TODO выброс ошибки, если такой объект есть в коллекции - if (comparer != null && _collection.Contains(obj)) + if (comparer != null && _collection.Contains(obj, comparer)) { throw new CollectionAlreadyExistsException(); } diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/MassiveGenericObjects.cs index f1e9429..9f8d6e7 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -62,10 +62,10 @@ public class MassiveGenericObjects : ICollectionGenericObjects } - public int Insert(T obj, IEqualityComparer? comparer = null) + public int Insert(T obj, IEqualityComparer? comparer = null) { // TODO выброс ошибки, если такой объект есть в коллекции - if (comparer != null && _collection.Contains(obj)) + if (comparer != null && _collection.Contains(obj, comparer)) { throw new CollectionAlreadyExistsException(); } @@ -84,10 +84,10 @@ public class MassiveGenericObjects : ICollectionGenericObjects } - public int Insert(T obj, int position, IEqualityComparer? comparer = null) + public int Insert(T obj, int position, IEqualityComparer? comparer = null) { // TODO выброс ошибки, если такой объект есть в коллекции - if (comparer != null && _collection.Contains(obj)) + if (comparer != null && _collection.Contains(obj, comparer)) { throw new CollectionAlreadyExistsException(); } diff --git a/ProjectTrolleybus/ProjectTrolleybus/Exceptions/CollectionAlreadyExistsException.cs b/ProjectTrolleybus/ProjectTrolleybus/Exceptions/CollectionAlreadyExistsException.cs index 05bb400..db15130 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/Exceptions/CollectionAlreadyExistsException.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/Exceptions/CollectionAlreadyExistsException.cs @@ -6,7 +6,7 @@ namespace ProjectTrolleybus.Exceptions; internal class CollectionAlreadyExistsException : ApplicationException { public CollectionAlreadyExistsException(CollectionInfo collectionInfo) : base("В коллекции уже есть такой элемент: " + collectionInfo) { } - public CollectionAlreadyExistsException() : base() { } + public CollectionAlreadyExistsException() : base("В коллекции уже есть такой элемент") { } public CollectionAlreadyExistsException(string message) : base(message) { } public CollectionAlreadyExistsException(string message, Exception exception) : base(message, exception) { } protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { } diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs index 0183c10..d5e1f01 100644 --- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs +++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs @@ -81,6 +81,11 @@ public partial class FormTrolleyBCollection : Form MessageBox.Show(ex.Message); _logger.LogError("Ошибка: {Message}", ex.Message); } + catch (CollectionAlreadyExistsException ex) + { + MessageBox.Show(ex.Message); + _logger.LogError("Ошибка: {Message}", ex.Message); + } }