Exemple #1
0
 /// <summary>
 /// 查找单个对象
 /// </summary>
 /// <typeparam name="T">数据类型</typeparam>
 /// <param name="array">数据类型的对象数组</param>
 /// <param name="handler">查找委托</param>
 /// <returns></returns>
 public static T Find <T>(T[] array, FindHandle <T> handler)
 {
     for (int i = 0; i < array.Length; i++)
     {
         if (handler(array[i]))
         {
             return(array[i]);
         }
     }
     return(default(T));
 }
Exemple #2
0
        /// <summary>
        /// 查找满足条件所有对象
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="array">数据类型对象数组</param>
        /// <param name="handler">查找委托</param>
        /// <returns></returns>
        public static T[] FindAll <T>(T[] array, FindHandle <T> handler)
        {
            List <T> list = new List <T>();

            for (int i = 0; i < array.Length; i++)
            {
                if (handler(array[i]))
                {
                    list.Add(array[i]);
                }
            }
            return(list.ToArray());
        }
Exemple #3
0
        private bool MoveToFirstFile(out Win32.WIN32_FIND_DATA findData)
        {
            FindHandle = Win32.FindFirstFile(GetPathAdaptedForSearch(SearchPath), out findData);
            if (FindHandle.IsValidHandle())
            {
                return(true);
            }

            var errorCode = Marshal.GetLastWin32Error();

            if (errorCode == Win32.ERROR_NO_MORE_FILES)
            {
                return(false);
            }

            throw new FileSystemException(SearchPath, errorCode.GetExceptionMessageForCulture(Thread.CurrentThread.CurrentCulture));
        }