表格重构

This commit is contained in:
2025-10-10 17:57:36 +08:00
parent bf2f6d2680
commit bf7b1bbbb2
133 changed files with 4481 additions and 1366 deletions

View File

@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace NBF
{
public interface IConfigContext
{
// 定义非泛型接口
}
public class ConfigContext<T> : IConfigContext where T : ConfigBase
{
private static List<T> _cacheList = new List<T>();
#region Cache
public void Association(List<T> list)
{
if (list != null)
{
_cacheList = list;
}
}
#endregion
public int Count()
{
return _cacheList.Count;
}
public int Count(Func<T, bool> predicate)
{
return _cacheList.Count(predicate);
}
public T Get(int key)
{
return First(key);
}
public T Fist()
{
return _cacheList.First();
}
public T Last()
{
return _cacheList.Last();
}
public T Fist(Predicate<T> match)
{
return Get(match);
}
public T Last(Predicate<T> match)
{
return _cacheList.FindLast(match);
}
public T Get(Predicate<T> match)
{
return _cacheList.Find(match);
}
public T GetRandom()
{
Random random = new Random();
// 随机从列表中取一个对象
return _cacheList[random.Next(_cacheList.Count)];
}
public List<T> GetList()
{
return _cacheList;
}
public List<T> GetList(Predicate<T> match)
{
return _cacheList.FindAll(match);
}
private T First(int key)
{
return _cacheList.Find(t => t.id == key);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 82dbb868b2724a85aa866e0bf9e88e91

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
namespace NBF
{
public static class Configs
{
private static readonly Dictionary<Type, IConfigContext> _dictionary = new Dictionary<Type, IConfigContext>();
static Configs()
{
}
public static ConfigContext<T> Table<T>() where T : ConfigBase
{
var type = typeof(T);
if (_dictionary.TryGetValue(type, out var context))
{
return context as ConfigContext<T>;
}
var jsonContext = new ConfigContext<T>();
_dictionary[type] = jsonContext;
return jsonContext;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1881c9eee25240ddbaecbf99546a8750

View File

@@ -0,0 +1,17 @@
using System;
namespace NBF
{
[AttributeUsage(AttributeTargets.Class)]
public class TableNameAttribute : Attribute
{
public string Name;
public string Key;
public TableNameAttribute(string name, string key = "id")
{
Name = name;
Key = key;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 737030131eba4fd6ba6067b47fcae5d3
timeCreated: 1744862554