49 lines
1.8 KiB
C#
49 lines
1.8 KiB
C#
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<int> collection, string separator)
|
|
{
|
|
if (collection == null) return null;
|
|
IEnumerable<string> 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<TEntity> Select<TEntity>(this int count, Func<int, TEntity> func)
|
|
{
|
|
var list = new List<TEntity>();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
list.Add(func(i));
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|
|
} |