private void SetupModelBinders(IInspectorContext context) { var alternateModelBinder = new ModelBinder(context.ProxyFactory); var binders = ModelBinders.Binders; var keys = binders.Keys.ToArray(); for (int i = 0; i < keys.Length; i++) { var type = keys[i]; var originalBinder = binders[type]; IModelBinder newBinder; if (alternateModelBinder.TryCreate(originalBinder, out newBinder)) { context.Logger.Info(Resources.ModelBinderInspectorSetupReplacedModelBinder, originalBinder.GetType()); binders[type] = newBinder; } } // handle default binder var originalDefaultBinder = ModelBinders.Binders.DefaultBinder as DefaultModelBinder; IModelBinder newDefaultBinder; if (originalDefaultBinder != null && alternateModelBinder.TryCreate(originalDefaultBinder, out newDefaultBinder)) { context.Logger.Info(Resources.ModelBinderInspectorSetupReplacedModelBinder, originalDefaultBinder.GetType()); ModelBinders.Binders.DefaultBinder = newDefaultBinder; } }
public void Setup(IInspectorContext context) { var originalDefaultBinder = ModelBinders.Binders.DefaultBinder; IModelBinder newDefaultBinder; var alternateModelBinder = new ModelBinder(context.ProxyFactory); if (originalDefaultBinder != null && alternateModelBinder.TryCreate(originalDefaultBinder, out newDefaultBinder)) { context.Logger.Info(Resources.ModelBinderInspectorSetupReplacedModelBinder, originalDefaultBinder.GetType()); ModelBinders.Binders.DefaultBinder = newDefaultBinder; } }