Пример #1
0
        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;
            }
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
 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;
     }
 }
Пример #4
0
        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;
            }
        }