Beispiel #1
0
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="typeList"></param>
        private static void ReadData(params Type[] typeList)
        {
            foreach (var type in typeList)
            {
                if (!DataFilePath.ContainsKey(type))
                {
                    DataFilePath.Add(type, StaticDao.GetDataFilePath(type, DataDirPath));
                }

                if (!GlobalData.ContainsKey(type))
                {
                    var data = StaticDao.ReadGlobalData(type, DataFilePath[type]);
                    GlobalData.Add(type, data);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获取数据列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static List <T> GetList <T>()
        {
            var      type = typeof(T);
            List <T> list = new List <T>();

            if (GlobalData == null)
            {
                return(list);
            }
            if (!GlobalData.ContainsKey(type))
            {
                return(list);
            }

            var dataList = GlobalData[type];

            if (dataList == null || dataList.Count <= 0)
            {
            }
            list = JArray.Parse(Util.JsonUtil.Serialize(dataList)).ToObject <List <T> >();
            return(list);
        }
Beispiel #3
0
        //public void ResyncGlobalData() => BaseScript.TriggerClientEvent("Session.UpdateGlobalData", ServerID, JsonConvert.SerializeObject(GlobalData));

        /// <summary>
        /// Gets the global data at the specified key if it exists
        /// </summary>
        /// <param name="key">Key of the entry you are wanting to get</param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public T GetGlobalData <T>(string key, T defaultValue = default(T)) => GlobalData.ContainsKey(key) ? (T)GlobalData[key] : defaultValue;