초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
using System.Reflection;
using ServerCore; using ServerBase;
namespace ServerBase;
public class MetaValidator
{
public void validate<T>(IReadOnlyList<T> list, ValidatorErrorCollection errors)
{
var thisAssembly = Assembly.GetExecutingAssembly();
var methods = thisAssembly.GetTypes()
.SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.Static))
.Where(x => x.GetCustomAttributes<MetaValidatorAttribute>().Any())
.Where(x => x.GetParameters()?[0]?.ParameterType == typeof(T))
.ToList();
if (methods.Count == 0)
{
Log.getLogger().error($"not found validateFunc. type: {typeof(T).Name}");
return;
}
var validateFunc = MethodInfoExtentions.compile<Action<T, ValidatorErrorCollection>>(methods[0]);
errors.CurrentName = typeof(T).Name;
// var invokeParams = new object[1];
foreach (var (item, i) in list.Select((value, i) => (value, i)))
{
errors.CurrentArrayIndex = i;
validateFunc.Invoke(item!, errors);
}
}
}