view 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
line wrap: on
line source

// 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 <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;

namespace IBBoard
{
	
	
	public class DictionaryToArrayConverter
	{
		/// <summary>
		/// Takes the set of values in a dictionary and returns them as an array of typed objects.
		/// </summary>
		/// <param name="dictionary">
		/// A <see cref="Dictionary`2"/> to extract an array of values from
		/// </param>
		/// <returns>
		/// An array of <see cref="VALUE_TYPE"/> objects taken from the Values property of the dictionary, or NULL if the dictionary is NULL
		/// </returns>
		public static  VALUE_TYPE[] Convert<KEY_TYPE, VALUE_TYPE>(Dictionary<KEY_TYPE, VALUE_TYPE> dictionary)
		{
			if (dictionary == null)
			{
				return null;
			}
			
			VALUE_TYPE[] col = new VALUE_TYPE[dictionary.Count];
			dictionary.Values.CopyTo(col, 0);
			return col;
		}
	}
}