From fd1c4bece40a0cbc6940359eb9c1d6e53e883cce Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 27 Oct 2021 07:41:15 -0400 Subject: [PATCH] improvements to HandleDictionary --- .../Collections/Generic/HandleDictionary.cs | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/MBS.Framework/Collections/Generic/HandleDictionary.cs b/MBS.Framework/Collections/Generic/HandleDictionary.cs index d1f31d1..4558082 100644 --- a/MBS.Framework/Collections/Generic/HandleDictionary.cs +++ b/MBS.Framework/Collections/Generic/HandleDictionary.cs @@ -21,27 +21,53 @@ using System; namespace MBS.Framework.Collections.Generic { - public class HandleDictionary + public class HandleDictionary : HandleDictionary { - private BidirectionalDictionary _dict = new BidirectionalDictionary(); - public TObject GetObject(IntPtr handle) + } + public class HandleDictionary + { + private BidirectionalDictionary _dict = new BidirectionalDictionary(); + + public int Count { get { return _dict.Count; } } + + public TObject GetObject(THandle handle) { return _dict.GetValue2(handle); } - public IntPtr GetHandle(TObject obj) + public THandle GetHandle(TObject obj) { return _dict.GetValue1(obj); } - - public void Add(IntPtr handle, TObject obj) + public void Add(THandle handle, TObject obj) { _dict.Add(handle, obj); } + /// + /// Removes the of the given . + /// + /// The object to remove. public void Remove(TObject obj) { _dict.RemoveByValue2(obj); } + /// + /// Removes the represented by the given . + /// + /// The handle of the to remove. + public void Remove(THandle handle) + { + _dict.RemoveByValue1(handle); + } + } + public static class HandleDictionaryExtensions + { + public static ushort Add(this HandleDictionary dict, TObject obj) + { + ushort index = (ushort)(dict.Count + 1); + dict.Add(index, obj); + return index; + } } }