예제 #1
0
        public static void DeleteData <T>(string textPath, DelCondition <T> condition)
        {
            if (!File.Exists(textPath))
            {
                return;
            }

            bool   isDelete = false;
            string res      = string.Empty;

            T[] tempArr = ReadTextDataArray <T>(textPath);

            for (int i = 0; i < tempArr.Length; i++)
            {
                if (!condition(tempArr[i]))
                {
                    res += JsonUtility.ToJson(tempArr[i]);
                }
                else
                {
                    isDelete = true;
                }
            }

            if (!isDelete || string.IsNullOrEmpty(res))
            {
                return;
            }

            File.Delete(textPath);
            Add(textPath, res);
        }
예제 #2
0
파일: DirectoryEx.cs 프로젝트: zqbb/MxDebug
        /// <summary>
        /// 读取目录中的文件
        /// </summary>
        /// <param name="folderPath">文件夹路径</param>
        /// <param name="condition">添加筛选条件</param>
        /// <returns></returns>
        public static FileInfo[] GetFiles(string folderPath, DelCondition <FileInfo> condition)
        {
            FileInfo[]      temp      = GetFiles(folderPath);
            List <FileInfo> fileInfos = new List <FileInfo>();

            for (int i = 0; i < temp.Length; i++)
            {
                if (!condition(temp[i]))
                {
                    continue;
                }
                fileInfos.Add(temp[i]);
            }

            return(fileInfos.ToArray());
        }
예제 #3
0
        private static T[] FindData <T>(string textPath, DelCondition <T> condition)
        {
            if (!File.Exists(textPath))
            {
                return(default(T[]));
            }

            List <T> tempList = new List <T>();

            T[] tempArr = ReadTextDataArray <T>(textPath);

            for (int i = 0; i < tempArr.Length; i++)
            {
                if (condition(tempArr[i]))
                {
                    tempList.Add(tempArr[i]);
                }
            }

            return(tempList.ToArray());
        }
예제 #4
0
        private static void ModifyData <T>(string textPath, T newData, DelCondition <T> condition, bool isCreate = true)
        {
            if (!File.Exists(textPath))
            {
                if (isCreate)
                {
                    Add <T>(textPath, newData);
                }
                return;
            }

            bool   isModify = false;
            string res      = string.Empty;

            T[] tempArr = ReadTextDataArray <T>(textPath);

            for (int i = 0; i < tempArr.Length; i++)
            {
                if (!condition(tempArr[i]))
                {
                    res += JsonUtility.ToJson(tempArr[i]);
                }
                else
                {
                    res     += JsonUtility.ToJson(newData);
                    isModify = true;
                }
            }

            if (!isModify || string.IsNullOrEmpty(res))
            {
                return;
            }
            File.Delete(textPath);
            Add(textPath, res);
        }
예제 #5
0
 /// <summary>
 /// 查找数据
 /// </summary>
 /// <typeparam name="T">泛型类数据(只能是Json可序列化类型)</typeparam>
 /// <param name="textPath">数据保存文本路径</param>
 /// <param name="condition">条件集合</param>
 /// <returns></returns>
 public static T[] Find <T>(string textPath, DelCondition <T> condition)
 {
     return(FindData <T>(textPath, condition));
 }
예제 #6
0
 /// <summary>
 /// 修改指定条件数据
 /// </summary>
 /// <param name="textPath">数据保存文本路径</param>
 /// <param name="newData">新数据</param>
 /// <param name="condition">条件集合</param>
 /// <param name="isCreate">修改数据不存在的情况下是否创建一条新数据</param>
 public static void Modify <T>(string textPath, T newData, DelCondition <T> condition, bool isCreate = true)
 {
     ModifyData <T>(textPath, newData, condition, isCreate);
 }
예제 #7
0
 /// <summary>
 /// 删除指定条件的数据
 /// </summary>
 /// <param name="textPath">数据保存文本路径</param>
 /// <param name="condition">筛选条件</param>
 public static void Delete <T>(string textPath, DelCondition <T> condition)
 {
     DeleteData <T>(textPath, condition);
 }
예제 #8
0
 public Event(DelCondition condition, State nextState, Action action)
 {
     this.condition = condition;
     this.nextState = nextState;
     this.action    = action;
 }