我IValueProvider为我的Web API项目创建了一些实现,我对该ContainsPrefix方法在接口上的用途感到困惑.
该ContainsPrefix方法有以下摘要评论:
确定集合是否包含指定的前缀.
然而,该方法的摘要是抽象的,并不解释prefix将向该方法提供什么或该方法所服务的功能.难道prefix会是动作参数的名字吗?动作名称?控制器名称?其中任何一个的前三个字母?此方法是否存在以自动确定IValueProvider应为哪个操作参数提供值?
我从来没有看到该ContainsPrefix方法由Web API框架被调用我的IValueProvider实现,虽然我确实看到网页API的参考CollectionModelBinder,MutableObjectModelBinder,SimpleModelBinderProvider,和CompositeValueProvider.例如,以下实现在我的测试中没有引起任何问题:
MyValueProvider:
public class MyValueProvider : IValueProvider
{
public bool ContainsPrefix(string prefix)
{
throw new NotYetImplementedException();
}
public ValueProviderResult GetValue(string key)
{
return new ValueProviderResult("hello", "hello", CultureInfo.InvariantCulture);
}
}
Run Code Online (Sandbox Code Playgroud)
的TestController:
public class TestController : ApiController
{
public string Get([ModelBinder]string input)
{
return input;
}
}
Run Code Online (Sandbox Code Playgroud)
GET对我的请求TestController将返回你好 …