Extentions.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Collections;
  15. namespace Xceed.Wpf.AvalonDock
  16. {
  17. internal static class Extensions
  18. {
  19. public static bool Contains(this IEnumerable collection, object item)
  20. {
  21. foreach (var o in collection)
  22. if (o == item)
  23. return true;
  24. return false;
  25. }
  26. public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
  27. {
  28. foreach (T v in collection)
  29. action(v);
  30. }
  31. public static int IndexOf<T>(this T[] array, T value) where T : class
  32. {
  33. for (int i = 0; i < array.Length; i++)
  34. if (array[i] == value)
  35. return i;
  36. return -1;
  37. }
  38. public static V GetValueOrDefault<V>(this WeakReference wr)
  39. {
  40. if (wr == null || !wr.IsAlive)
  41. return default(V);
  42. return (V)wr.Target;
  43. }
  44. }
  45. }