From ab26cc40f4701e6a64798a02516ecd3c3e845f44 Mon Sep 17 00:00:00 2001 From: Mike Baker <1426795+mbaker3@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:20:48 -0400 Subject: [PATCH] AbstractContentManager - Cleanup Make use of Dictionary<,>.TryGetValue --- Content/AbstractContentManager.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Content/AbstractContentManager.cs b/Content/AbstractContentManager.cs index 7a0676a..4eac3e3 100644 --- a/Content/AbstractContentManager.cs +++ b/Content/AbstractContentManager.cs @@ -100,12 +100,11 @@ public AbstractContentManager AddGroup(ContentGroupConfigVO configVO) /// Occurs when the passed in ID is not found. to check beforehand. public AbstractContentManager RemoveGroup(string contentGroupID) { - if (!m_ContentGroups.ContainsKey(contentGroupID)) + if (!m_ContentGroups.TryGetValue(contentGroupID, out AbstractContentGroup contentGroup)) { throw new ArgumentException($"Tried to remove Content Group with ID {contentGroupID} but none exists!"); } - AbstractContentGroup contentGroup = m_ContentGroups[contentGroupID]; m_ContentGroups.Remove(contentGroupID); contentGroup.Dispose(); @@ -120,12 +119,12 @@ public AbstractContentManager RemoveGroup(string contentGroupID) /// Occurs when the passed in ID is not found. to check beforehand. public AbstractContentGroup GetGroup(string contentGroupID) { - if (!m_ContentGroups.ContainsKey(contentGroupID)) + if (!m_ContentGroups.TryGetValue(contentGroupID, out AbstractContentGroup group)) { throw new ArgumentException($"Tried to get Content Group with ID {contentGroupID} but none exists!"); } - return m_ContentGroups[contentGroupID]; + return group; } /// @@ -148,12 +147,11 @@ public void Show(AbstractContentController contentController) { string contentGroupID = contentController.ContentGroupID; - if (!m_ContentGroups.ContainsKey(contentGroupID)) + if (!m_ContentGroups.TryGetValue(contentGroupID, out AbstractContentGroup contentGroup)) { throw new ArgumentException($"ContentGroupID of {contentGroupID} does not exist in the Content Manager. Did you add the Content Group?"); } - AbstractContentGroup contentGroup = m_ContentGroups[contentGroupID]; contentGroup.Show(contentController); } @@ -164,13 +162,12 @@ public void Show(AbstractContentController contentController) /// true if found and cleared, false if not found. A warning will be logged public bool ClearGroup(string contentGroupID) { - if (!m_ContentGroups.ContainsKey(contentGroupID)) + if (!m_ContentGroups.TryGetValue(contentGroupID, out AbstractContentGroup contentGroup)) { Logger.Warning($"ContentGroupID of {contentGroupID} does not exist in the Content Manager. Did you add the Content Group?"); return false; } - AbstractContentGroup contentGroup = m_ContentGroups[contentGroupID]; contentGroup.Clear(); return true;