/// Extension methods for IEnumerable
///
public static class IEnumerableExtensions
{
///
/// Splits a list into list of buckets
///
///
/// values
/// Bucket size
///
public static IEnumerable
{
if (chunkSize <= 0)
{
throw new ArgumentException("chunkSize should be greater than zero");
}
if (values.IsNullOrEmpty())
{
throw new ArgumentException("value is either empty or null to Split");
}
while (values.Any())
{
yield return values.Take(chunkSize);
values = values.Skip(chunkSize);
}
}
///
/// Converts IEnumerable intp CSV
///
///
/// values
///
public static String ToCSV
{
const string comma = ",";
if (values.IsNullOrEmpty())
{
throw new ArgumentException("value is either empty or null");
}
return String.Join(comma, values.ToStrings
}
///
/// Converts IEnumerable<T> to IEnumerable<String>
///
///
/// values
///
public static IEnumerable
{
if (values.IsNullOrEmpty())
{
throw new ArgumentException("value is either empty or null");
}
foreach(var value in values)
{
yield return value.ToString();
}
}
///
/// checks if the list contains any elements
///
///
/// values
///
public static bool IsNullOrEmpty
{
if (values.IsNull() || values.Count() == 0)
{
return true;
}
return false;
}
}
No comments:
Post a Comment