using System.Reflection; using ServerCore; using ServerBase; namespace ServerBase; public class MetaValidator { public void validate(IReadOnlyList list, ValidatorErrorCollection errors) { var thisAssembly = Assembly.GetExecutingAssembly(); var methods = thisAssembly.GetTypes() .SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.Static)) .Where(x => x.GetCustomAttributes().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>(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); } } }