using System; namespace Gallery.Util { public static class Extensions { public static int IndexOf(this T[] array, Predicate predicate) { for (var i = 0; i < array.Length; i++) { if (predicate(array[i])) { return i; } } return -1; } public static int LastIndexOf(this T[] array, Predicate predicate) { for (var i = array.Length - 1; i >= 0; i--) { if (predicate(array[i])) { return i; } } return -1; } public static bool All(this T[] array, Predicate predicate) { for (var i = 0; i < array.Length; i++) { if (!predicate(array[i])) { return false; } } return true; } public static bool AnyFor(this T[] array, int from, int to, Predicate predicate) { for (var i = from; i <= to; i++) { if (predicate(array[i])) { return true; } } return false; } public static DateTime ToLocalTime(this long time) { //return new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(time).ToLocalTime(); return new DateTime(621355968000000000L + time * 10000000).ToLocalTime(); } public static long ToTimestamp(this DateTime datetime) { var ticks = datetime.Ticks; return (ticks - 621355968000000000L) / 10000000; } } }