using System; using System.Collections.Generic; using System.Globalization; using System.Linq; namespace Kit.Helpers { public static class SystemIntegerExtensionMethods { public static string ToMonthName(this int monthNo) { if (monthNo < 1 || monthNo > 12) { throw new ArgumentOutOfRangeException("monthNo", monthNo, "monthNo must be one of 1..12"); } var dateTimeFormat = new CultureInfo("ru-RU").DateTimeFormat; return dateTimeFormat.GetMonthName(monthNo); } public static string ToMonthNamea(this int monthNo) { if (monthNo < 1 || monthNo > 12) { throw new ArgumentOutOfRangeException("monthNo", monthNo, "monthNo must be one of 1..12"); } var monthNames = new string[] { "января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря" }; return monthNames[monthNo - 1]; } public static string Join(this IEnumerable collection, string separator) { if (collection == null) return null; IEnumerable stringCollection = collection.Select(x => x.ToString()); return stringCollection.ToArray().Join(separator); } public static bool InRange(this int value, int rangeStart, int rangeEnd) { return value >= rangeStart && value <= rangeEnd; } public static IEnumerable Select(this int count, Func func) { var list = new List(); for (int i = 0; i < count; i++) { list.Add(func(i)); } return list; } } }