# HG changeset patch # User IBBoard # Date 1232881418 0 # Node ID 25b953087465c36e1ea22e12b8ceb73f50f81566 # Parent 6b762694f05175d3e25667589caa647c3fad4200 * Rename DictionaryToArrayConverter to DictionaryUtils * Add method to merge arrays no-open-ticket diff -r 6b762694f051 -r 25b953087465 Collections/DictionaryToArrayConverter.cs --- a/Collections/DictionaryToArrayConverter.cs Tue Jan 06 19:27:47 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -// DictionaryToArrayConverter.cs is a part of the IBBoard utils library (referred to from here as "this program") -// -// Copyright (C) 2009 IBBoard -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . -// - -using System; -using System.Collections.Generic; - -namespace IBBoard -{ - - - public class DictionaryToArrayConverter - { - /// - /// Takes the set of values in a dictionary and returns them as an array of typed objects. - /// - /// - /// A to extract an array of values from - /// - /// - /// An array of objects taken from the Values property of the dictionary, or NULL if the dictionary is NULL - /// - public static VALUE_TYPE[] Convert(Dictionary dictionary) - { - if (dictionary == null) - { - return null; - } - - int entryCount = dictionary.Count; - VALUE_TYPE[] col = new VALUE_TYPE[entryCount]; - - if (entryCount > 0) - { - dictionary.Values.CopyTo(col, 0); - } - - return col; - } - } -} diff -r 6b762694f051 -r 25b953087465 Collections/DictionaryUtils.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Collections/DictionaryUtils.cs Sun Jan 25 11:03:38 2009 +0000 @@ -0,0 +1,80 @@ +// DictionaryToArrayConverter.cs is a part of the IBBoard utils library (referred to from here as "this program") +// +// Copyright (C) 2009 IBBoard +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using System; +using System.Collections.Generic; + +namespace IBBoard +{ + public class DictionaryUtils + { + /// + /// Takes the set of values in a dictionary and returns them as an array of typed objects. + /// + /// + /// A to extract an array of values from + /// + /// + /// An array of objects taken from the Values property of the dictionary, or NULL if the dictionary is NULL + /// + public static VALUE_TYPE[] Convert(IDictionary dictionary) + { + if (dictionary == null) + { + return null; + } + + int entryCount = dictionary.Count; + VALUE_TYPE[] col = new VALUE_TYPE[entryCount]; + + if (entryCount > 0) + { + dictionary.Values.CopyTo(col, 0); + } + + return col; + } + + /// + /// Takes two dictionaries and merges them. If a key exists in both dictionaries then the value in firstDictionary takes priority. + /// + /// + /// The to merge values in to + /// + /// + /// The of values to merge in + /// + /// + /// A made by adding values from secondDictionary where the key didn't exist in firstDictionary + /// + public static IDictionary Merge(IDictionary firstDictionary, IDictionary secondDictionary) + { + Dictionary mergedDictionary = new Dictionary(firstDictionary); + + foreach (KEY_TYPE key in secondDictionary.Keys) + { + if (!mergedDictionary.ContainsKey(key)) + { + mergedDictionary.Add(key, secondDictionary[key]); + } + } + + return mergedDictionary; + } + } +} diff -r 6b762694f051 -r 25b953087465 IBBoard.mdp --- a/IBBoard.mdp Tue Jan 06 19:27:47 2009 +0000 +++ b/IBBoard.mdp Sun Jan 25 11:03:38 2009 +0000 @@ -45,7 +45,7 @@ - + @@ -53,5 +53,6 @@ + \ No newline at end of file