简体   繁体   中英

WebAPI Custom ModelBinder inheritance

I am trying to bind to the parent of a certain object type using WebAPI BindParameter. I am able to bind to the object itself (SomeObject), but not its parent (SomeOtherObject). This would cause me to have to have a specific BindParameter call for all possible inheritors of SomeObject. Is there a better way to bind the parameter type that would allow me to accomplish this?

The binders:

GlobalConfiguration.Configuration.BindParameter(typeof(SomeObject), new SetTrackerModelBinder()); 

GlobalConfiguration.Configuration.BindParameter(typeof(SomeOtherObject), new SetTrackerModelBinder()); //Does not work. 

The object structure:

public class SomeObject:SomeOtherObject{

}
public class AnotherObject:SomeOtherObject{

}
public class SomeOtherObject{

}

The action:

public void PostStuffs(SomeObject value) {}

You can try looking at my answer to the following post. I do not use ModelBinders though:

WebApi Model Binding For Inherited Types

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM