using Microsoft.AspNetCore.Mvc.ModelBinding; using System; using System.Collections.Generic; using System.Linq; namespace WIDESEA_Core.ModelBinder { public class BaseBinderProvider : IModelBinderProvider { public List<Type> types = new List<Type>(); // public List<BinderObject> binder=new BinderObject() public BaseBinderProvider() { types.Add(typeof(Dictionary<string, object>)); InitType(); } private void AddType(Type type) { if (!types.Any(x => x == type)) { types.Add(type); } } private void InitType() { AddType(typeof(Dictionary<string, object>)); AddType(typeof(List<Dictionary<string, object>>)); AddType(typeof(List<object>)); AddType(typeof(List<WIDESEA_Entity.DomainModels.Sys_TableColumn>)); AddType(typeof(WIDESEA_Entity.DomainModels.Sys_TableInfo)); } /// <summary> /// å¢žåŠ ä¸€ä¸ªå§”æ‰˜ç”¨äºŽè°ƒç”¨ return new BaseModelBinder();æ—¶å¯¹å‚æ•°è¿›è¡Œè¡Œæ ¡éªŒï¼Œå¾…完.. /// </summary> /// <param name="types"></param> public BaseBinderProvider(List<Type> 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; } } }