From 7ffbdd02cb8a856e8ddef00edb6c629a5ab8fa8b Mon Sep 17 00:00:00 2001 From: Anatoly Brizhan Date: Tue, 5 Mar 2024 18:01:05 +0100 Subject: [PATCH] Add public validation method --- Assets/BetterLocators/Runtime/Locator.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Assets/BetterLocators/Runtime/Locator.cs b/Assets/BetterLocators/Runtime/Locator.cs index 15aa069..51d7fde 100644 --- a/Assets/BetterLocators/Runtime/Locator.cs +++ b/Assets/BetterLocators/Runtime/Locator.cs @@ -11,8 +11,7 @@ public class Locator public virtual void Register(T item) where T : TItem { var type = item.GetType(); - - if (_services.ContainsKey(type)) + if (HasRegistered()) { var message = $"Service of type {type} is already registered. Operation cancelled"; Debug.LogError(message); @@ -22,11 +21,16 @@ public virtual void Register(T item) where T : TItem _services[type] = item; } + public virtual bool HasRegistered() where T : TItem + { + var type = typeof(T); + return _services.ContainsKey(type); + } + public virtual void Unregister(T service) where T : TItem { var type = service.GetType(); - - if (!_services.ContainsKey(type)) + if (!HasRegistered()) { var message = $"Item of type {type} is not registered. Operation cancelled"; Debug.LogError(message);