Example #1
0
        private IModelBinder GetBinder(Type modelType, IModelBinder fallbackBinder)
        {
            // Try to look up a binder for this type. We use this order of precedence:
            // 1. Binder returned from provider
            // 2. Binder registered in the global table
            // 3. Binder attribute defined on the type
            // 4. Supplied fallback binder

            IModelBinder binder = _modelBinderProviders.GetBinder(modelType);

            if (binder != null)
            {
                return(binder);
            }

            if (_innerDictionary.TryGetValue(modelType, out binder))
            {
                return(binder);
            }

            binder = ModelBinders.GetBinderFromAttributes(modelType,
                                                          () => String.Format(CultureInfo.CurrentCulture, MvcResources.ModelBinderDictionary_MultipleAttributes, modelType.FullName));

            return(binder ?? fallbackBinder);
        }
Example #2
0
        private IModelBinder GetBinder(Type modelType, IModelBinder fallbackBinder)
        {
            // Try to look up a binder for this type. We use this order of precedence:
            // 1. Binder returned from provider
            // 2. Binder registered in the global table
            // 3. Binder attribute defined on the type
            // 4. Supplied fallback binder

            IModelBinder binder = _modelBinderProviders.GetBinder(modelType);

            if (binder != null)
            {
                return(binder);
            }

            if (_innerDictionary.TryGetValue(modelType, out binder))
            {
                return(binder);
            }

            // Function is called frequently, so ensure the error delegate is stateless
            binder = ModelBinders.GetBinderFromAttributes(modelType, (Type errorModel) =>
            {
                throw new InvalidOperationException(
                    String.Format(CultureInfo.CurrentCulture, MvcResources.ModelBinderDictionary_MultipleAttributes, errorModel.FullName));
            });

            return(binder ?? fallbackBinder);
        }