using PlcSiemens.Core.Common;

namespace PlcSiemens.Core.Extension
{
    /// <summary>
    /// 数组集合扩展功能
    /// </summary>
    public static class ArrayExtension
    {
        /// <summary>
        /// 判断数组是否为空
        /// </summary>
        /// <typeparam name="T">数组类型</typeparam>
        /// <param name="targer">目标对象</param>
        /// <returns></returns>
        public static bool IsNullOrEmpty<T>(this T[] targer)
        {
            if (targer == null || targer.Length < 1)
                return true;
            return false;
        }

        /// <summary>
        /// 判断数组是否为空
        /// </summary>
        /// <typeparam name="T">数组类型</typeparam>
        /// <param name="targer">目标对象</param>
        /// <param name="predicate">搜索条件</param>
        /// <returns></returns>
        public static T Find<T>(this T[] targer, Predicate<T> predicate)
        {
            Argument.IsNotEmpty(targer, "targer");
            return Array.Find(targer, predicate);
        }

        /// <summary>
        /// 判断数组是否为空
        /// </summary>
        /// <typeparam name="T">数组类型</typeparam>
        /// <param name="targer">目标对象</param>
        /// <param name="predicate">搜索条件</param>
        /// <returns></returns>
        public static T[] FindAll<T>(this T[] targer, Predicate<T> predicate)
        {
            Argument.IsNotEmpty(targer, "targer");
            return Array.FindAll(targer, predicate);
        }
    }
}
