﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace DotNetPlus.ExtensionMethods
{
	/// <summary>
	/// Extension methods for the System.Collections.Generic.Dictionary class.
	/// </summary>
	public static class DictionaryExtensions
	{
		public static Dictionary<TKey, TValue> Shuffle<TKey, TValue>(this Dictionary<TKey, TValue> dictionary)
		{
			return dictionary.Shuffle().ToDictionary(item => item.Key, item => item.Value);
		}

		public static T GetValue<TKey, TValue, T>(this Dictionary<TKey, TValue> dictionary, TKey key, T defaultValue)
		{
			try
			{
				object read_object = dictionary[key];

				return
					read_object != null
					? CommonFunctions.ConvertValue(read_object.ToString().Trim(), defaultValue)
					: defaultValue;
			}
			catch
			{
				return defaultValue;
			}
		}
	}
}
