// ***********************************************************************
// Assembly : Construction
// Author : zjx
// Created : 09-16-2020
//
// Last Modified By : zjx
// Last Modified On : 09-16-2020
// ***********************************************************************
//
// Copyright (c) jindongfang. All rights reserved.
//
//
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
namespace WellWorkDataUI
{
///
/// Class EnumerableExtensions.
///
public static class EnumerableExtensions
{
///
/// Orders the by list.
///
/// The type of the t source.
/// The type of the t order.
/// The source.
/// The order.
/// The equal.
/// IEnumerable<TSource>.
public static IEnumerable OrderByList(this IEnumerable source, IEnumerable order, Func equal)
{
IEnumerable result = from s in source
from o in order.Select((v, i) => new { obj = v, index = i })
where equal(s, o.obj)
orderby o.index
select s;
return result.Union(source.Where(r => !order.Any(k => equal(r, k))));
}
///
/// MinOrDefault
///
/// t
/// sequence
/// T
public static T MinOrDefault(this IEnumerable sequence)
{
if (sequence.Any())
{
return sequence.Min();
}
else
{
return default(T);
}
}
///
/// MaxOrDefault
///
/// t
/// sequence
/// T
public static T MaxOrDefault(this IEnumerable sequence)
{
if (sequence.Any())
{
return sequence.Max();
}
else
{
return default(T);
}
}
///
/// SumOrDefault
///
/// t
/// sequence
/// T
public static double? SumOrDefault(this IEnumerable sequence)
{
if (sequence.Any())
{
return sequence.Sum();
}
else
{
return default(double?);
}
}
}
}