mvc2 里面的 ValueProvider
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
Justification = "This property is settable so that unit tests can provide mock implementations.")]
public IDictionary<string, ValueProviderResult> ValueProvider {
get {
if (_valueProvider == null) {
_valueProvider = new ValueProviderDictionary(ControllerContext);
}
return _valueProvider;
}
set {
_valueProvider = value;
}
}
mvc3里的ValueProvider
public IValueProvider ValueProvider {
get {
if (_valueProvider == null) {
_valueProvider = ValueProviderFactories.Factories.GetValueProvider(ControllerContext);
}
return _valueProvider;
}
set {
_valueProvider = value;
}
}
public static class ValueProviderFactories {
private static readonly ValueProviderFactoryCollection _factories = new ValueProviderFactoryCollection() {
new ChildActionValueProviderFactory(),
new FormValueProviderFactory(),
new JsonValueProviderFactory(),
new RouteDataValueProviderFactory(),
new QueryStringValueProviderFactory(),
new HttpFileCollectionValueProviderFactory(),
};
public static ValueProviderFactoryCollection Factories {
get {
return _factories;
}
}
private static object GetDeserializedObject(ControllerContext controllerContext) {
if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase)) {
// not JSON request
return null;
}
StreamReader reader = new StreamReader(controllerContext.HttpContext.Request.InputStream);
string bodyText = reader.ReadToEnd();
if (String.IsNullOrEmpty(bodyText)) {
// no JSON data
return null;
}
public override IValueProvider GetValueProvider(ControllerContext controllerContext) {
if (controllerContext == null) {
throw new ArgumentNullException("controllerContext");
}