namespace DeltaGroup.WheelOfJeopardy.Util
{
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
public static class Extensions
{
#region Methods
///
/// Shuffles the specified list.
///
/// The type of the E.
/// The list.
///
public static List Shuffle(this List list)
{
// so we dont remove from original
var temp = new List(list);
var result = new List();
var r = new Random();
while (temp.Count > 0)
{
var randomIndex = r.Next(0, temp.Count);
result.Add(temp[randomIndex]);
//remove to avoid duplicates
temp.RemoveAt(randomIndex);
}
return result;
}
///
/// Toes the int.
///
/// The s.
///
public static int ToInt(this string s)
{
int i;
return int.TryParse(s, out i) ? i : 0;
}
///
/// Finds the visual child.
///
///
/// The dep obj.
///
public static T FindVisualChild(DependencyObject depObj)
where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
return (T)child;
}
T childItem = FindVisualChild(child);
if (childItem != null) return childItem;
}
}
return null;
}
#endregion Methods
}
}