using Microsoft.AspNetCore.Mvc.ModelBinding; using System; using System.Collections.Generic; using System.Linq; namespace WIDESEA_Core.ModelBinder { public class BaseBinderProvider : IModelBinderProvider { public List types = new List(); // public List binder=new BinderObject() public BaseBinderProvider() { types.Add(typeof(Dictionary)); InitType(); } private void AddType(Type type) { if (!types.Any(x => x == type)) { types.Add(type); } } private void InitType() { AddType(typeof(Dictionary)); AddType(typeof(List>)); AddType(typeof(List)); AddType(typeof(List)); AddType(typeof(WIDESEA_Entity.DomainModels.Sys_TableInfo)); } /// /// 增加一个委托用于调用 return new BaseModelBinder();时对参数进行行校验,待完.. /// /// public BaseBinderProvider(List types) { this.types = types ?? throw new Exception("types初始化不能为null"); InitType(); } public IModelBinder GetBinder(ModelBinderProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (types.Any(x => x == context.Metadata.ModelType)) { return new BaseModelBinder();// new BinderTypeModelBinder(typeof(TableInfoEntityBinder)); } return null; } } }