comparison Collections/DictionaryToArrayConverter.cs @ 12:465b672e9682

Closes #5 - Dictionary to array converter * Handled null dictionary * Fixed casting problems * Added documentation Also remove rogue Console.Write in LogNotifier
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Jan 2009 18:45:32 +0000
parents ba9239164de2
children 6b762694f051
comparison
equal deleted inserted replaced
11:ba9239164de2 12:465b672e9682
23 { 23 {
24 24
25 25
26 public class DictionaryToArrayConverter 26 public class DictionaryToArrayConverter
27 { 27 {
28 /// <summary>
29 /// Takes the set of values in a dictionary and returns them as an array of typed objects.
30 /// </summary>
31 /// <param name="dictionary">
32 /// A <see cref="Dictionary`2"/> to extract an array of values from
33 /// </param>
34 /// <returns>
35 /// An array of <see cref="VALUE_TYPE"/> objects taken from the Values property of the dictionary, or NULL if the dictionary is NULL
36 /// </returns>
28 public static VALUE_TYPE[] Convert<KEY_TYPE, VALUE_TYPE>(Dictionary<KEY_TYPE, VALUE_TYPE> dictionary) 37 public static VALUE_TYPE[] Convert<KEY_TYPE, VALUE_TYPE>(Dictionary<KEY_TYPE, VALUE_TYPE> dictionary)
29 { 38 {
30 VALUE_TYPE[] col = (VALUE_TYPE[]) new object[dictionary.Count]; 39 if (dictionary == null)
40 {
41 return null;
42 }
43
44 VALUE_TYPE[] col = new VALUE_TYPE[dictionary.Count];
31 dictionary.Values.CopyTo(col, 0); 45 dictionary.Values.CopyTo(col, 0);
32 return (VALUE_TYPE[])col; 46 return col;
33 } 47 }
34 } 48 }
35 } 49 }