コード例 #1
0
        /// <summary>
        /// 获取所有排序后的符合条件的数据表行。
        /// </summary>
        /// <param name="condition" > 要检查的条件。</param>
        /// <param name="comparison" > 要排序的条件。</param>
        /// <returns>所有排序后的符合条件的数据表行。</returns>
        public static TestDataTable[] GetAllDataRows(System.Predicate <TestDataTable> condition, System.Comparison <TestDataTable> comparison)
        {
            if (condition == null)
            {
                throw new System.Exception("Condition is invalid.");
            }

            if (comparison == null)
            {
                throw new System.Exception("Comparison is invalid.");
            }

            List <TestDataTable> results = new List <TestDataTable>();

            foreach (var dataRow in GetInstance()._dict)
            {
                TestDataTable dr = dataRow.Value;
                if (condition(dr))
                {
                    results.Add(dr);
                }
            }

            results.Sort(comparison);
            return(results.ToArray());
        }
コード例 #2
0
        /// <summary>
        /// 获取所有数据表行。
        /// </summary>
        /// <returns>所有数据表行。</returns>
        public static TestDataTable[] GetAllDataRows()
        {
            int index = 0;

            TestDataTable[] allDataRows = new TestDataTable[GetInstance().Count];
            foreach (var dataRow in GetInstance()._dict)
            {
                allDataRows[index++] = dataRow.Value;
            }

            return(allDataRows);
        }
コード例 #3
0
        /// <summary>
        /// Do reload the dataTable file: Test
        /// </summary>
        void _ReloadAll(bool throwWhenDuplicatePrimaryKey, string customContent = null)
        {
            for (var j = 0; j < TabFilePaths.Length; j++)
            {
                var       tabFilePath = TabFilePaths[j];
                TableFile tableFile;
                if (customContent == null)
                {
                    tableFile = DataTableModule.Get(tabFilePath, false);
                }
                else
                {
                    tableFile = TableFile.LoadFromString(customContent);
                }

                using (tableFile)
                {
                    foreach (var row in tableFile)
                    {
                        var           pk = TestDataTable.ParsePrimaryKey(row);
                        TestDataTable dataTable;
                        if (!_dict.TryGetValue(pk, out dataTable))
                        {
                            dataTable           = new TestDataTable(row);
                            _dict[dataTable.Id] = dataTable;
                        }
                        else
                        {
                            if (throwWhenDuplicatePrimaryKey)
                            {
                                throw new System.Exception(string.Format("DuplicateKey, Class: {0}, File: {1}, Key: {2}", this.GetType().Name, tabFilePath, pk));
                            }
                            else
                            {
                                dataTable.Reload(row);
                            }
                        }
                    }
                }
            }

            if (OnReload != null)
            {
                OnReload();
            }

            ReloadCount++;
            UnityEngine.Debug.LogFormat("Reload dataTables: {0}, Row Count: {1}, Reload Count: {2}", GetType(), Count, ReloadCount);
        }
コード例 #4
0
        /// <summary>
        /// 获取符合条件的数据表行。
        /// </summary>
        /// <param name="condition" > 要检查的条件。</param>
        /// <returns>符合条件的数据表行。</returns>
        /// <remarks>当存在多个符合条件的数据表行时,仅返回第一个符合条件的数据表行。</remarks>
        public static TestDataTable GetDataRow(System.Predicate <TestDataTable> condition)
        {
            if (condition == null)
            {
                throw new System.Exception("Condition is invalid.");
            }

            foreach (var dataRow in GetInstance()._dict)
            {
                TestDataTable dr = dataRow.Value;
                if (condition(dr))
                {
                    return(dr);
                }
            }

            return(null);
        }