From 2e54b38d2bbac372f45e4428dea19b6e745cab64 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Fri, 3 Mar 2023 11:49:32 +0800 Subject: [PATCH] Supplement Insert methods for pair list. --- .../Common/Collections/Generic/IPairList.cs | 2 ++ .../Common/Collections/Generic/PairList.cs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Assets/Cryville/Common/Collections/Generic/IPairList.cs b/Assets/Cryville/Common/Collections/Generic/IPairList.cs index 02783df..d1b0bea 100644 --- a/Assets/Cryville/Common/Collections/Generic/IPairList.cs +++ b/Assets/Cryville/Common/Collections/Generic/IPairList.cs @@ -4,8 +4,10 @@ using System.Collections.Generic; namespace Cryville.Common.Collections.Generic { public interface IPairList : IList { void Add(object key, object value); + void Insert(int index, object key, object value); } public interface IPairList : IList>, IPairList { void Add(TKey key, TValue value); + void Insert(int index, TKey key, TValue value); } } diff --git a/Assets/Cryville/Common/Collections/Generic/PairList.cs b/Assets/Cryville/Common/Collections/Generic/PairList.cs index ffc8348..62311ba 100644 --- a/Assets/Cryville/Common/Collections/Generic/PairList.cs +++ b/Assets/Cryville/Common/Collections/Generic/PairList.cs @@ -6,6 +6,10 @@ namespace Cryville.Common.Collections.Generic { public void Add(object key, object value) { Add(new KeyValuePair(key, value)); } + + public void Insert(int index, object key, object value) { + Insert(index, new KeyValuePair(key, value)); + } } public class PairList : List>, IPairList { public void Add(TKey key, TValue value) { @@ -20,5 +24,18 @@ namespace Cryville.Common.Collections.Generic { throw new ArgumentException("Wrong key type or value type"); } } + + public void Insert(int index, TKey key, TValue value) { + Insert(index, new KeyValuePair(key, value)); + } + + public void Insert(int index, object key, object value) { + try { + Insert(index, (TKey)key, (TValue)value); + } + catch (InvalidCastException) { + throw new ArgumentException("Wrong key type or value type"); + } + } } }