public void MultipleBindersCannotBeRegisteredForSameType()
        {
            var dictionary = new ModelBinderDictionary(new DefaultModelBinder());

            dictionary.Add(typeof(DataSet), FakeBinder);
            Assert.Throws <ArgumentException>(() => dictionary.Add(typeof(DataSet), FakeBinder));
        }
Exemple #2
0
 protected override void Load(ContainerBuilder builder)
 {
     binders.Add(typeof(PageName), new ImplicitAssignmentBinder());
     binders.Add(typeof(int[]), new ArrayBinder());
     binders.Add(typeof(FileUpload), new UploadBinder());
     binders.Add(typeof(EntryRevision), new EntryRevisionBinder());
 }
 public static void RegisterGlobalBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(DateTime), new DateTimeBinder());
     binders.Add(typeof(DateTime?), new DateTimeBinder());
     binders.Add(typeof(Decimal), new DecimalModelBinder());
     binders.Add(typeof(Decimal?), new DecimalModelBinder());
 }
        public static void RegisterXrmModels(ModelBinderDictionary binders)
        {
            var customEntityModelBinder = new EntityModelBinder();

            if (Config != null)
            {
                foreach (ModelBindingElement modelBinding in Config.ModelBindings)
                {
                    var type = GetType($"{Config.ModelNamespace}.{modelBinding.Type}");
                    if (type != null)
                    {
                        lock (Locker)
                        {
                            if (!binders.ContainsKey(type))
                            {
                                binders.Add(type, customEntityModelBinder);
                            }
                        }

                        if (modelBinding.Enumerable)
                        {
                            type = typeof(IEnumerable <>).MakeGenericType(type);
                            lock (Locker)
                            {
                                if (!binders.ContainsKey(type))
                                {
                                    binders.Add(type, customEntityModelBinder);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        public static void Register(ModelBinderDictionary binder)
        {
            binder.Add(typeof(ObjectId), new ObjectIdBinder());

            binder.Add(typeof(string[]), new StringArrayBinder());

            binder.Add(typeof(int[]), new IntArrayBinder());
        }
 public static void RegisterModelBinders(ModelBinderDictionary modelBinderDictionary)
 {
     modelBinderDictionary.Add(typeof(FacebookAuthResponse), new JsonModelBinder<FacebookAuthResponse>("authResponse"));
     modelBinderDictionary.Add(typeof(FacebookNotificationResponse), new JsonModelBinder<FacebookNotificationResponse>("facebookNotificationResponse"));
     modelBinderDictionary.Add(typeof(VerseEngineeringUser), new VerseEngineeringUserBinder());
     modelBinderDictionary.Add(typeof(FacebookAccessToken), DependencyResolver.Current.GetService<FacebookAccessTokenModelBinder>());
     modelBinderDictionary.Add(typeof(HideCandidateVersesFlag), new HideCandidateVersesFlagModelBinder());
 }
        public static void RegisterModelBinders(ModelBinderDictionary modelBinders, HttpConfiguration config)
        {
            modelBinders.Add(typeof(ArticleId), new ArticleIdModelBinder());
            modelBinders.Add(typeof(ArticleRevisionDate), new ArticleRevisionDateModelBinder());
            modelBinders.Add(typeof(bool?), new BooleanModelBinder());
            modelBinders.Add(typeof(bool), new BooleanModelBinder());

            AddWebApiModelBinder(config, typeof(ArticleId), new ArticleIdModelBinder());
            AddWebApiModelBinder(config, typeof(ArticleRevisionDate), new ArticleRevisionDateModelBinder());
        }
        public static void RegisterModelBinders(ModelBinderDictionary modelBinders, HttpConfiguration config)
        {
            modelBinders.Add(typeof(ArticleSlug), new ArticleSlugModelBinder());
            modelBinders.Add(typeof(ArticleRevisionDate), new ArticleRevisionDateModelBinder());
            modelBinders.Add(typeof(bool?), new BooleanModelBinder());
            modelBinders.Add(typeof(bool), new BooleanModelBinder());

            AddWebApiModelBinder(config, typeof(ArticleSlug), new ArticleSlugModelBinder());
            AddWebApiModelBinder(config, typeof(ArticleRevisionDate), new ArticleRevisionDateModelBinder());
        }
        public void RemoveCanBeUsedToUnregister()
        {
            var dictionary = new ModelBinderDictionary(new DefaultModelBinder());

            dictionary.Add(typeof(DataSet), FakeBinder);
            dictionary.Remove(FakeBinder);
            dictionary.Add(typeof(DataSet), FakeBinder);
            dictionary.Remove(FakeBinder);
            dictionary.Add(typeof(DataSet), FakeBinder);
        }
        public MvcApplication(IControllerFactory controllerFactory, IContentProvider contentProvider, RouteCollection routes)
        {
            if (controllerFactory == null)
            {
                throw new ArgumentNullException("controllerFactory");
            }
            if (contentProvider == null)
            {
                throw new ArgumentNullException("contentProvider");
            }

            ControllerFactory = controllerFactory;
            ContentProvider   = contentProvider;

            Routes      = routes;
            ViewEngines = new ViewEngineCollection()
            {
                new RazorViewEngineSimulator(this)
            };
            Bundles         = new BundleCollection();
            FilterProviders = new FilterProviderCollection();
            foreach (var provider in System.Web.Mvc.FilterProviders.Providers)
            {
                FilterProviders.Add(provider);
            }

            ModelMetadataProvider = ModelMetadataProviders.Current;
            WebViewPageFactory    = new WebViewPageFactory(Assemblies, GetNamespaces(this));

            Binders = new ModelBinderDictionary();
            foreach (var b in ModelBinders.Binders)
            {
                Binders.Add(b);
            }
        }
Exemple #11
0
        /// <summary>
        /// Register this binder in specified ModelBinderDictionary
        /// </summary>
        public static DefaultValueModelBinder <T> Register(ref ModelBinderDictionary binders)
        {
            var binder = new DefaultValueModelBinder <T>();

            binders.Add(typeof(T), binder);
            return(binder);
        }
Exemple #12
0
        public static object Register(ref ModelBinderDictionary binders, params Expression <Func <T, object> >[] fieldNameExp)
        {
            var binder = new InnerJsonModelBinder <T>(fieldNameExp);

            binders.Add(typeof(T), binder);
            return(binder);
        }
        /// <summary>
        /// Register this binder in specified ModelBinderDictionary
        /// </summary>
        public static DefaultForMissingValueModelBinder <TModel> Register(ModelBinderDictionary binders)
        {
            var binder = new DefaultForMissingValueModelBinder <TModel>();

            binders.Add(typeof(TModel), binder);
            return(binder);
        }
        /// <summary>
        /// Register this binder in specified ModelBinderDictionary
        /// </summary>
        public static CustomModelBinder <TModel> Register(ModelBinderDictionary binders)
        {
            var binder = new CustomModelBinder <TModel>();

            binders.Add(typeof(TModel), binder);
            return(binder);
        }
Exemple #15
0
 public LyniconBinder()
 {
     // Use this as the default binder in the scope of BindModel on this binder only
     var binders = new ModelBinderDictionary();
     ModelBinders.Binders.Do(kvp => binders.Add(kvp.Key, kvp.Value));
     binders.DefaultBinder = this;
     this.Binders = binders;
 }
 /// <summary>Registers the model binder to the specified model binder dictionary.</summary>
 /// <param name="binders">The model binder dictionary to add to.</param>
 /// <remarks>
 /// Typical usage:
 /// <example>
 /// protected override void Application_Start()
 /// {
 ///     base.Application_Start();
 ///     TypeConverterModelBinder.RegisterForAll(ModelBinders.Binders);
 /// }
 /// </example>
 /// </remarks>
 public static void RegisterForAll(ModelBinderDictionary binders)
 {
     Guard.NotNull(binders, "binders");
     foreach (var tp in TypeConverters.Keys)
     {
         binders.Add(tp, TypeConverterModelBinder.Instance);
     }
 }
        public void ClearCanBeUsedToRemoveAllRegistrations()
        {
            var dictionary = new ModelBinderDictionary(new DefaultModelBinder());

            dictionary.Add(typeof(DataSet), FakeBinder);
            Assert.IsTrue(dictionary.Contains(FakeBinder));
            dictionary.Clear();
            Assert.IsFalse(dictionary.Contains(FakeBinder));
        }
Exemple #18
0
        public LyniconBinder()
        {
            // Use this as the default binder in the scope of BindModel on this binder only
            var binders = new ModelBinderDictionary();

            ModelBinders.Binders.Do(kvp => binders.Add(kvp.Key, kvp.Value));
            binders.DefaultBinder = this;
            this.Binders          = binders;
        }
Exemple #19
0
 public static void RegisterModelBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(DateTime), new DateTimeBinder());
     binders.Add(typeof(DateTime?), new DateTimeBinder());
     binders.Add(typeof(TimeSpan), new TimeSpanBinder());
     binders.Add(typeof(TimeSpan?), new TimeSpanBinder());
     binders.Add(typeof(double), new DoubleModelBinder());
     binders.Add(typeof(double?), new DoubleModelBinder());
     binders.Add(typeof(decimal), new DecimalModelBinder());
     binders.Add(typeof(decimal?), new DecimalModelBinder());
 }
Exemple #20
0
 /// <summary>
 ///     Registriert die im System zu verwendenden ModelBinder.
 ///     Dazu müssen die ModelBinder der übergebenen ModelBinder-Liste hinzugefügt werden.
 /// </summary>
 /// <param name="modelBinders">Liste/Dictionary der die ModelBinder hinzugefügt werden müssen.</param>
 public static void RegisterModelBindings(ModelBinderDictionary modelBinders)
 {
     ModelBinderProviders.BinderProviders.Add(new EntityModelBinderProvider());
     //ModelBinderProviders.BinderProviders.Add(new InvariantCultureModelBinderProvider(typeof(double),
     //    typeof(double?),
     //    typeof(decimal),
     //    typeof(decimal?)));
     ModelBinderProviders.BinderProviders.Add(new FileInfoModelBinderProvider());
     modelBinders.Add(typeof(ISessionBindable), new SessionModelBinder());
 }
        public void ShouldResolveBindersViaInheritance()
        {
            var dictionary = new ModelBinderDictionary(new DefaultModelBinder());

            dictionary.Add(typeof(IListSource), FakeBinder);

            var binder = dictionary.GetBinder(typeof(DataSet)); // DataSet implements IListSource

            Assert.AreSame(FakeBinder, binder);
        }
        public void ShouldResolveBinder()
        {
            var dictionary = new ModelBinderDictionary(new DefaultModelBinder());

            dictionary.Add(typeof(DataSet), FakeBinder);

            var binder = dictionary.GetBinder(typeof(DataSet));

            Assert.AreSame(FakeBinder, binder);
        }
        public void ShouldFallBackToDefaultBinder()
        {
            var dictionary = new ModelBinderDictionary(new DefaultModelBinder());

            dictionary.Add(typeof(DataSet), FakeBinder);

            var binder = dictionary.GetBinder(typeof(int));

            Assert.IsInstanceOf <DefaultModelBinder>(binder);
        }
Exemple #24
0
 public virtual void RegisterModelBinders(ModelBinderProviderCollection providers, ModelBinderDictionary binders)
 {
     foreach (var p in BinderProviders)
     {
         providers.Add(p);
     }
     foreach (var b in Binders)
     {
         binders.Add(b.Metadata.TargetType, b.Value);
     }
 }
        public void ContainsCanBeUsedToCheckForPriorRegistration()
        {
            var dictionary = new ModelBinderDictionary(new DefaultModelBinder());

            Assert.IsFalse(dictionary.Contains(FakeBinder));

            dictionary.Add(typeof(DataSet), FakeBinder);
            Assert.IsTrue(dictionary.Contains(FakeBinder));

            dictionary.Remove(FakeBinder);
            Assert.IsFalse(dictionary.Contains(FakeBinder));
        }
Exemple #26
0
 public static void RegisterModelBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(decimal), new NumericModelBinder <decimal>());
     binders.Add(typeof(decimal?), new NumericModelBinder <decimal?>());
     binders.Add(typeof(int), new NumericModelBinder <int>());
     binders.Add(typeof(int?), new NumericModelBinder <int?>());
     binders.Add(typeof(long), new NumericModelBinder <long>());
     binders.Add(typeof(long?), new NumericModelBinder <long?>());
     binders.Add(typeof(CalendarControl), new CalendarModelBinder());
 }
 public void Bind(ModelBinderDictionary binders)
 {
     binders.Add(typeof(Coordinates), new CoordinatesModelBinder());
     binders.Add(typeof(State), new StateModelBinder());
     binders.Add(typeof(Country), new CountryModelBinder());
     binders.Add(typeof(Elevation), new ElevationModelBinder());
     binders.Add(typeof(Distance), new DistanceModelBinder());
     binders.Add(typeof(Volume), new VolumeModelBinder());
     binders.Add(typeof(HeightMeasurements), new HeightMeasurementModelBinder());
 }
Exemple #28
0
        private void RegisterModelBinders()
        {
            ModelBinderDictionary binders     = ModelBinders.Binders;
            DTOModelBinder        modelBinder = new DTOModelBinder();

            binders.Add(typeof(PartnerCompanyInfoDTO), modelBinder);
            binders.Add(typeof(PartnerCredentialDTO), modelBinder);
            binders.Add(typeof(PartnerPersonalInfoDTO), modelBinder);
            binders.Add(typeof(PartnerPreferencesDTO), modelBinder);
            binders.Add(typeof(PropertyDTO), modelBinder);
            binders.Add(typeof(PropertyFeatureDetailDTO), modelBinder);
            binders.Add(typeof(PropertyPictureDTO), modelBinder);
            binders.Add(typeof(ManagementSalesController.PublishPropertyDTO), modelBinder);
        }
Exemple #29
0
        public static void RegisterBinders(ModelBinderDictionary binders)
        {
            binders.Add(typeof(Artist), new ArtistBinder());
            binders.Add(typeof(Article), new BaseWithImagesBinder());
            binders.Add(typeof(Release), new ReleaseBinder());

            //Binders that return null for these types so that they could be easily removed from their respective sets
            binders.Add(typeof(Reference), new IKnowIfImEmptyBinder());
            binders.Add(typeof(Track), new IKnowIfImEmptyBinder());

            //Binders that remove empty elements from sets
            binders.Add(typeof(ReferenceSet), new SetBinder <Reference>());     //new ReferenceSetBinder());
            binders.Add(typeof(Tracklist), new SetBinder <Track>());            //new TracklistBinder());
            binders.Add(typeof(LocalStringSet), new SetBinder <LocalString>()); //new LocalStringSetBinder());
        }
Exemple #30
0
		public static void RegisterBinders(ModelBinderDictionary binders)
		{
			var types = Assembly.GetCallingAssembly().GetTypes();

			foreach (var binderType in types.Where(x => x.BaseType == typeof(DefaultModelBinder)))
			{
				var binder = (IModelBinder)Activator.CreateInstance(binderType);
				var modelName = binderType.Name.Substring(0, binderType.Name.Length - "Binder".Length);

				var type = types.First(y => y.Name == modelName);

				binders.Add(type, binder);
			}
		}
Exemple #31
0
        public static void RegisterBinders(ModelBinderDictionary binders)
        {
            var types = Assembly.GetCallingAssembly().GetTypes();

            foreach (var binderType in types.Where(x => x.BaseType == typeof(DefaultModelBinder)))
            {
                var binder    = (IModelBinder)Activator.CreateInstance(binderType);
                var modelName = binderType.Name.Substring(0, binderType.Name.Length - "Binder".Length);

                var type = types.First(y => y.Name == modelName);

                binders.Add(type, binder);
            }
        }
Exemple #32
0
        public static void RegisterBinders(ModelBinderDictionary binders)
        {
            // Model => FormPost
            binders.Add(typeof(TH.Core.Tools.Form.Models.FormPost), new TH.WebUI.Tools.Form.ModelBinders.FormPostBinder());
            binders.Add(typeof(IEnumerable <TH.Core.Tools.Form.Models.FormPost>), new TH.WebUI.Tools.Form.ModelBinders.FormPostBinder());

            // Model => Metadata
            binders.Add(typeof(TH.Core.Tools.Form.Models.Metadata), new TH.WebUI.Tools.Form.ModelBinders.MetadataBinder());

            // Model => JArray
            binders.Add(typeof(Newtonsoft.Json.Linq.JArray), new TH.WebUI.Base.ModelBinding.JsonBinder());

            // Model => JObject
            binders.Add(typeof(Newtonsoft.Json.Linq.JObject), new TH.WebUI.Base.ModelBinding.JsonBinder());

            // Model => FlexParam
            binders.Add(typeof(TH.WebUI.Base.ModelBinding.IDParam), new TH.WebUI.Base.ModelBinding.IDParamBinder());
        }
        protected static void Establish(Type[] types = null, bool isAjax = true)
        {
            typeof(DispatcherControllerBase).GetField("types", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, new List <Type>());

            dispatcher = Pleasure.Mock <IDispatcher>();
            IoCFactory.Instance.StubTryResolve(dispatcher.Object);
            controller = new FakeDispatcher();

            var requestBase = Pleasure.MockAsObject <HttpRequestBase>(mock =>
            {
                if (isAjax)
                {
                    mock.SetupGet(r => r.Headers).Returns(new NameValueCollection {
                        { "X-Requested-With", "XMLHttpRequest" }
                    });
                }

                mock.SetupGet(r => r.Form).Returns(new NameValueCollection()
                {
                    { "[0].Name", "Value" },
                    { "[1].Name", "Value" },
                });
            });

            controller.ControllerContext = new ControllerContext(Pleasure.MockStrictAsObject <HttpContextBase>(mock => mock.SetupGet(r => r.Request).Returns(requestBase)), new RouteData(), controller);
            controller.ValueProvider     = Pleasure.MockStrictAsObject <IValueProvider>(mock => mock.Setup(r => r.GetValue(Pleasure.MockIt.IsAny <string>())).Returns(new ValueProviderResult(string.Empty, string.Empty, Thread.CurrentThread.CurrentCulture)));

            var modelBinderDictionary = new ModelBinderDictionary();
            var modelBinder           = Pleasure.MockAsObject <IModelBinder>(mock => mock.Setup(r => r.BindModel(Pleasure.MockIt.IsAny <ControllerContext>(),
                                                                                                                 Pleasure.MockIt.IsAny <ModelBindingContext>())));

            foreach (var type in types.Recovery(new Type[] { }))
            {
                modelBinderDictionary.Add(type, modelBinder);
            }
            controller.SetValue("Binders", modelBinderDictionary);
        }
 public static void RegisterModelBinders(ModelBinderDictionary binder)
 {
     binder.Add(typeof(DateTime?), new DateModelBinder());
 }
Exemple #35
0
 public static void RegisterBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(EntidadeExterna), new EntidadeExternaBinder());
 }
 public static void RegisterBinders(ModelBinderDictionary modelBinderDictionary)
 {
     modelBinderDictionary.Add(typeof (FilterRequest), new LegacyFilterRequestModelBinder());
 }
Exemple #37
0
 protected override void RegisterModelBinders(ModelBinderDictionary binders)
 {
     binders.Add<RestRequest, RestRequestModelBinder>(Container);
 }
 private static void RegisterModelBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof (DegreeType), new DegreeTypeModelBinder());
 }
Exemple #39
0
 public static void RegisterModelBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(IUser), new UserModelBinder());
 }
 public static void RegisterBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(GridSettings), new GridSettingsModelBinder());
 }
 internal static void RegisterModelBinders(ModelBinderDictionary modelBinderDictionary)
 {
     modelBinderDictionary.Add(typeof(CreateOrEditPostModel), new CreateOrEditPostCustomDataBinder());
 }
 public static void RegisterModelBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(CustomerData), new CustomFieldNameModelBinder());
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="current"></param>
 public static void RegisterBindings(ModelBinderDictionary current)
 {
     current.Add(typeof(ProductRequest), new ProductRequestBinder());
 }
 public static void Register(ModelBinderDictionary binders)
 {
     var htmlStringEncodingModelBinder = new HtmlStringEncodingModelBinder();
     binders.Add(typeof(string), htmlStringEncodingModelBinder);
 }
 /// <summary>
 /// Globally-used model binders
 /// </summary>
 public static void Register(ModelBinderDictionary modelBinders)
 {
     modelBinders.DefaultBinder = new CustomModelBinder();
     modelBinders.Add(typeof(BirthDateModelBinder), new BirthDateModelBinder());
 }
Exemple #46
0
 public static void RegisterModelBinders(ModelBinderDictionary modelBinders)
 {
     modelBinders.Add(new KeyValuePair<Type, IModelBinder>(typeof (FileModel), new FileModelBinder()));
 }
 /// <summary>Registers the model binder to the specified model binder dictionary.</summary>
 /// <param name="binders">The model binder dictionary to add to.</param>
 /// <remarks>
 /// Typical usage:
 /// <example>
 /// protected override void Application_Start()
 /// {
 ///     base.Application_Start();
 ///     TypeConverterModelBinder.RegisterForAll(ModelBinders.Binders);
 /// }
 /// </example>
 /// </remarks>
 public static void RegisterForAll(ModelBinderDictionary binders)
 {
     Guard.NotNull(binders, "binders");
     foreach (var tp in TypeConverters.Keys)
     {
         binders.Add(tp, TypeConverterModelBinder.Instance);
     }
 }
 public static void RegisterModelBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(SearchCollection), new SearchCollectionModelBinder());
 }
 public static void RegisterBinders(ModelBinderDictionary binders)
 {
     binders.UseAuthorizationModelBinder();
     binders.Add(typeof(string), new TrimStringModelBinder());
 }
 public static void Register(ModelBinderDictionary modelBinders)
 {
     if (!modelBinders.ContainsKey(typeof(UploadStatus)))
         modelBinders.Add(typeof(UploadStatus), new UploadStatusModelBinder());
 }
 public static void RegisterModelBinders(ModelBinderDictionary binders)
 {
     binders.Add(typeof(decimal), new DecimalModelBinder());
     binders.Add(typeof(decimal?), new DecimalModelBinder());
 }