C# 将通用参数绑定到Web API中的自定义模型绑定器

C# 将通用参数绑定到Web API中的自定义模型绑定器,c#,generics,asp.net-web-api,model-binding,C#,Generics,Asp.net Web Api,Model Binding,在WebAPI的Register()方法中,我将特定参数类型绑定到自定义模型绑定器,如下所示: config.BindParameter(typeof(Expression<Func<Person, bool>>), new CustomModelBinder()); config.BindParameter(typeof(Expression),新的CustomModelBinder()); 如何对泛型类型进行相同的复制?除了Person,我还有更多的模型和DTO。

在WebAPI的Register()方法中,我将特定参数类型绑定到自定义模型绑定器,如下所示:

config.BindParameter(typeof(Expression<Func<Person, bool>>), new CustomModelBinder());
config.BindParameter(typeof(Expression),新的CustomModelBinder());

如何对泛型类型进行相同的复制?除了Person,我还有更多的模型和DTO。

尝试使用所有DTO实现的标记接口来实现

public interface IDataTransferObject {}

public class Person : IDataTransferObject
{
    ...
}
然后,您应该能够将这些绑定到自定义模型绑定器

config.BindParameter(typeof(Expression<Func<IDataTransferObject, bool>>), new CustomModelBinder());
config.BindParameter(typeof(Expression),新的CustomModelBinder());