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); } } } } } } }
public void DefaultModelBinders() { // Act ModelBinderDictionary binders = ModelBinders.Binders; // Assert Assert.AreEqual(3, binders.Count); Assert.IsTrue(binders.ContainsKey(typeof(byte[])), "Did not contain entry for byte[]."); Assert.IsInstanceOfType(binders[typeof(byte[])], typeof(ByteArrayModelBinder), "Did not contain correct binder for byte[]."); Assert.IsTrue(binders.ContainsKey(typeof(HttpPostedFileBase)), "Did not contain entry for HttpPostedFileBase."); Assert.IsInstanceOfType(binders[typeof(HttpPostedFileBase)], typeof(HttpPostedFileBaseModelBinder), "Did not contain correct binder for HttpPostedFileBase."); Assert.IsTrue(binders.ContainsKey(typeof(Binary)), "Did not contain entry for Binary."); Assert.IsInstanceOfType(binders[typeof(Binary)], typeof(LinqBinaryModelBinder), "Did not contain correct binder for Binary."); }
public void DefaultModelBinders() { // Act ModelBinderDictionary binders = ModelBinders.Binders; // Assert Assert.Equal(4, binders.Count); Assert.True(binders.ContainsKey(typeof(byte[]))); Assert.IsType <ByteArrayModelBinder>(binders[typeof(byte[])]); Assert.True(binders.ContainsKey(typeof(HttpPostedFileBase))); Assert.IsType <HttpPostedFileBaseModelBinder>(binders[typeof(HttpPostedFileBase)]); Assert.True(binders.ContainsKey(typeof(Binary))); Assert.IsType <LinqBinaryModelBinder>(binders[typeof(Binary)]); Assert.True(binders.ContainsKey(typeof(CancellationToken))); Assert.IsType <CancellationTokenModelBinder>(binders[typeof(CancellationToken)]); }
public void BindersProperty() { // Act ModelBinderDictionary binders = ModelBinders.Binders; // Assert Assert.AreEqual(1, binders.Count); Assert.IsTrue(binders.ContainsKey(typeof(HttpPostedFileBase)), "Did not contain entry for HttpPostedFileBase."); Assert.IsInstanceOfType(binders[typeof(HttpPostedFileBase)], typeof(HttpPostedFileBaseModelBinder), "Did not contain correct binder for HttpPostedFileBase."); }
protected override void Load(ContainerBuilder builder) { if (!binders.ContainsKey(typeof(PageName))) { binders.Add(typeof(PageName), new ImplicitAssignmentBinder()); } if (!binders.ContainsKey(typeof(int[]))) { binders.Add(typeof(int[]), new ArrayBinder()); } if (!binders.ContainsKey(typeof(FileUpload))) { binders.Add(typeof(FileUpload), new UploadBinder()); } if (!binders.ContainsKey(typeof(EntryRevision))) { binders.Add(typeof(EntryRevision), new EntryRevisionBinder()); } }
public static void Register(ModelBinderDictionary modelBinders) { if (!modelBinders.ContainsKey(typeof(UploadStatus))) modelBinders.Add(typeof(UploadStatus), new UploadStatusModelBinder()); }