qinchulong
2025-03-29 039a4a5433e7f80adc88b491b549e5d9486e4f9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
        }
    }
}