本文整理汇总了C#中ModelBinderDictionary类的典型用法代码示例。如果您正苦于以下问题:C# ModelBinderDictionary类的具体用法?C# ModelBinderDictionary怎么用?C# ModelBinderDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelBinderDictionary类属于命名空间,在下文中一共展示了ModelBinderDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBinderResolvesBindersWithCorrectPrecedence
public void GetBinderResolvesBindersWithCorrectPrecedence() {
// Proper order of precedence:
// 1. Binder registered in the global table
// 2. Binder attribute defined on the type
// 3. Default binder
// Arrange
IModelBinder registeredFirstBinder = new Mock<IModelBinder>().Object;
ModelBinderDictionary binders = new ModelBinderDictionary() {
{ typeof(MyFirstConvertibleType), registeredFirstBinder }
};
IModelBinder defaultBinder = new Mock<IModelBinder>().Object;
binders.DefaultBinder = defaultBinder;
// Act
IModelBinder binder1 = binders.GetBinder(typeof(MyFirstConvertibleType));
IModelBinder binder2 = binders.GetBinder(typeof(MySecondConvertibleType));
IModelBinder binder3 = binders.GetBinder(typeof(object));
// Assert
Assert.AreSame(registeredFirstBinder, binder1, "First binder should have been matched in the registered binders table.");
Assert.IsInstanceOfType(binder2, typeof(MySecondBinder), "Second binder should have been matched on the type.");
Assert.AreSame(defaultBinder, binder3, "Third binder should have been the fallback.");
}
示例2: ShouldBindAnEnumValue
public void ShouldBindAnEnumValue()
{
var collection = new ValueProviderCollection();
var nameValueCollection = new NameValueCollection
{
{"someVariable", EnumFixture.Value2.Name}
};
collection.Add(new FormCollection(nameValueCollection));
var modelMetadata = new ModelMetadata(new EmptyModelMetadataProvider(), null, null, typeof(EnumFixture), "someProperty");
var bindingContext = new ModelBindingContext
{
ModelMetadata = modelMetadata,
ValueProvider = collection,
ModelName = "someVariable"
};
var binderDictionary = new ModelBinderDictionary();
var binder = new EnumModelBinder(binderDictionary);
var retrieved = binder.BindModel(null, bindingContext);
Assert.IsInstanceOfType(retrieved, typeof(EnumFixture));
var @enum = retrieved as EnumFixture;
Assert.AreEqual(EnumFixture.Value2, @enum);
}
示例3: BinderShouldBindValues
public void BinderShouldBindValues() {
var controllerContext = new ControllerContext();
var binders = new ModelBinderDictionary {
{ typeof(Foo), new DefaultModelBinder() }
};
var input = new FormCollection {
{ "fooInstance[Bar1].Value", "bar1value" },
{ "fooInstance[Bar2].Value", "bar2value" }
};
var foos = new[] {
new Foo {Name = "Bar1", Value = "uno"},
new Foo {Name = "Bar2", Value = "dos"},
new Foo {Name = "Bar3", Value = "tres"},
};
var providers = new EmptyModelMetadataProvider();
var bindingContext = new ModelBindingContext {
ModelMetadata = providers.GetMetadataForType(() => foos, foos.GetType()),
ModelName = "fooInstance",
ValueProvider = input.ToValueProvider()
};
var binder = new KeyedListModelBinder<Foo>(binders, providers, foo => foo.Name);
var result = (IList<Foo>)binder.BindModel(controllerContext, bindingContext);
Assert.That(result.Count, Is.EqualTo(3));
Assert.That(result[0].Value, Is.EqualTo("bar1value"));
Assert.That(result[1].Value, Is.EqualTo("bar2value"));
}
示例4: EnumModelBinder
public EnumModelBinder(ModelBinderDictionary binders)
{
if (binders == null)
throw new ArgumentNullException("binders");
_defaultBinder = binders.DefaultBinder;
binders.DefaultBinder = this;
}
示例5: Register
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets)
{
RegisterController<WizardController>(container);
//RegisterGlobalAsset(globalAssets, "wizard.css");
RegisterPage(container, new Page("Wizard") //master page
{
Assets = new[] { new Asset("wizard.css", WizardAssetGroup) },
Areas = new[] { "content", "tail" },
SupportedScopes = SupportedScopes.EntireSite
});
RegisterPage(container, new Page("WizardBasicSettings", "Wizard"));
RegisterPage(container, new Page("WizardComplete", "Wizard"));
RegisterPage(container, new Page("WizardSetupChoice", "Wizard")
{
Areas = new[] { "setupOptions" },
SupportedScopes = SupportedScopes.EntireSite
});
RegisterPage(container, new Page("WizardTestInstall", "Wizard"));
RegisterPage(container, new Page("WizardThemeChoice", "Wizard"));
this.AddRoute(routes, new SiteRoute() { Name = "Wizard", Route = new Route("Wizard/{action}",
new RouteValueDictionary(new { controller = "Wizard" }), new MvcRouteHandler()), Merit = DefaultMerit });
this.AddRoute(routes, new SiteRoute()
{
Name = "WizardCatchAll",
Route = new Route("{*all}", new RouteValueDictionary(new
{
controller = "Wizard",
action = "CatchAll"
}), new MvcRouteHandler()),
Merit = (int)MeritLevel.High + 10000
});
}
示例6: Register
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets)
{
container.Configure(x =>
{
x.For<IAtomPubService>().Singleton().Add<AtomPubService>();
//this is default controller for all, no name given
x.For<IController>().Add<AtomPubController>();
});
RegisterController<AtomPubController>(container);
RegisterRoutes<AtomPubRouteRegistrar>(container, routes);
//register main site master page
RegisterPage(container, new Page("Site")
{
Areas = new[] { "head", "nav", "content", "sidetop", "sidemid", "sidebot", "foot", "tail" },
SupportedScopes = SupportedScopes.EntireSite | SupportedScopes.Workspace | SupportedScopes.Collection | SupportedScopes.Entry
});
//register other pages
RegisterPage(container, new Page("AtomPubIndex", "Site")
{
SupportedScopes = SupportedScopes.EntireSite | SupportedScopes.Collection | SupportedScopes.Workspace
});
RegisterPage(container, new Page("AtomPubResource", "Site")
{
SupportedScopes = SupportedScopes.Entry
});
}
示例7: Register
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets)
{
container.Configure(x => x.For<IAnnotateService>().Singleton().Add<AnnotateService>());
RegisterController<AnnotateController>(container);
RegisterWidget<AnnotateListWidget>(container);
RegisterRoutes<AnnotateRouteRegistrar>(container, routes);
}
示例8: LyniconBinder
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;
}
示例9: RegisterModelBinders
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());
}
示例10: Register
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets)
{
container.Configure(c => c.For<IRaterService>().Add<RaterService>());
RegisterController<RaterController>(container);
RegisterWidget<RaterWidget>(container);
RegisterRoutes<RaterRouteRegistrar>(container, routes);
}
示例11: RegisterModelBindersTests
public RegisterModelBindersTests()
{
modelBinders = new ModelBinderDictionary();
modelBinder = new FakeModelBinder();
serviceLocator = new Mock<FakeServiceLocator>();
registration = new RegisterModelBinders(modelBinders);
}
示例12: DefaultBinderProperty
public void DefaultBinderProperty() {
// Arrange
ModelBinderDictionary binders = new ModelBinderDictionary();
IModelBinder binder = new Mock<IModelBinder>().Object;
// Act & assert
MemberHelper.TestPropertyWithDefaultInstance(binders, "DefaultBinder", binder);
}
示例13: CreateDefaultBinderDictionary
private static ModelBinderDictionary CreateDefaultBinderDictionary() {
// We can't add a binder to the HttpPostedFileBase type as an attribute, so we'll just
// prepopulate the dictionary as a convenience to users.
ModelBinderDictionary binders = new ModelBinderDictionary() {
{ typeof(HttpPostedFileBase), new HttpPostedFileBaseModelBinder() }
};
return binders;
}
示例14: RegisterModelBinders
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());
}
示例15: DefaultBinderIsInstanceOfDefaultModelBinder
public void DefaultBinderIsInstanceOfDefaultModelBinder() {
// Arrange
ModelBinderDictionary binders = new ModelBinderDictionary();
// Act
IModelBinder defaultBinder = binders.DefaultBinder;
// Assert
Assert.IsInstanceOfType(defaultBinder, typeof(DefaultModelBinder));
}