本文整理汇总了C#中ModelBinderDictionary类的典型用法代码示例。如果您正苦于以下问题:C# ModelBinderDictionary类的具体用法?C# ModelBinderDictionary怎么用?C# ModelBinderDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelBinderDictionary类属于命名空间,在下文中一共展示了ModelBinderDictionary类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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.");
}
开发者ID:consumentor,项目名称:Server,代码行数:25,代码来源:ModelBinderDictionaryTest.cs
示例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);
}
开发者ID:dnfeitosa,项目名称:Dnfeitosa.Enums,代码行数:28,代码来源:EnumModelBinderTest.cs
示例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"));
}
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:34,代码来源:KeyedListModelBinderTests.cs
示例4: EnumModelBinder
public EnumModelBinder(ModelBinderDictionary binders)
{
if (binders == null)
throw new ArgumentNullException("binders");
_defaultBinder = binders.DefaultBinder;
binders.DefaultBinder = this;
}
开发者ID:dnfeitosa,项目名称:Dnfeitosa.Enums,代码行数:7,代码来源:EnumModelBinder.cs
示例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
});
}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:35,代码来源:WizardPlugin.cs
示例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
});
}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:31,代码来源:AtomPubPlugin.cs
示例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);
}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:8,代码来源:AnnotatePlugin.cs
示例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;
}
开发者ID:jamesej,项目名称:lynicon,代码行数:8,代码来源:LyniconBinder.cs
示例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());
}
开发者ID:jorik041,项目名称:VerseEngineering,代码行数:8,代码来源:WebApiConfig.cs
示例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);
}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:8,代码来源:RaterPlugin.cs
示例11: RegisterModelBindersTests
public RegisterModelBindersTests()
{
modelBinders = new ModelBinderDictionary();
modelBinder = new FakeModelBinder();
serviceLocator = new Mock<FakeServiceLocator>();
registration = new RegisterModelBinders(modelBinders);
}
开发者ID:GTuritto,项目名称:AspNetMvcExtensibility,代码行数:8,代码来源:RegisterModelBindersTests.cs
示例12: DefaultBinderProperty
public void DefaultBinderProperty() {
// Arrange
ModelBinderDictionary binders = new ModelBinderDictionary();
IModelBinder binder = new Mock<IModelBinder>().Object;
// Act & assert
MemberHelper.TestPropertyWithDefaultInstance(binders, "DefaultBinder", binder);
}
开发者ID:consumentor,项目名称:Server,代码行数:8,代码来源:ModelBinderDictionaryTest.cs
示例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;
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:9,代码来源:ModelBinders.cs
示例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());
}
开发者ID:sebnilsson,项目名称:WikiDown,代码行数:10,代码来源:ModelBinderConfig.cs
示例15: DefaultBinderIsInstanceOfDefaultModelBinder
public void DefaultBinderIsInstanceOfDefaultModelBinder() {
// Arrange
ModelBinderDictionary binders = new ModelBinderDictionary();
// Act
IModelBinder defaultBinder = binders.DefaultBinder;
// Assert
Assert.IsInstanceOfType(defaultBinder, typeof(DefaultModelBinder));
}
开发者ID:ledgarl,项目名称:Samples,代码行数:10,代码来源:ModelBinderDictionaryTest.cs
示例16: DefaultBinderIsInstanceOfDefaultModelBinder
public void DefaultBinderIsInstanceOfDefaultModelBinder() {
// Arrange
ModelBinderDictionary binders = new ModelBinderDictionary();
// Act
IModelBinder defaultBinder = binders.DefaultBinder;
// Assert
Assert.AreEqual(typeof(DefaultModelBinder), defaultBinder.GetType());
}
开发者ID:consumentor,项目名称:Server,代码行数:10,代码来源:ModelBinderDictionaryTest.cs
示例17: RegisterBinder
public static void RegisterBinder(ModelBinderDictionary binders) {
FileCollectionModelBinder binder = new FileCollectionModelBinder();
binders[typeof(HttpPostedFileBase[])] = binder;
binders[typeof(IEnumerable<HttpPostedFileBase>)] = binder;
binders[typeof(ICollection<HttpPostedFileBase>)] = binder;
binders[typeof(IList<HttpPostedFileBase>)] = binder;
binders[typeof(Collection<HttpPostedFileBase>)] = binder;
binders[typeof(List<HttpPostedFileBase>)] = binder;
}
开发者ID:ledgarl,项目名称:Samples,代码行数:10,代码来源:FileCollectionModelBinder.cs
示例18: BindModel
// Ensures that when JSON is deserialized null strings become empty.strings before persisting to the database.
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
bindingContext.ModelMetadata.ConvertEmptyStringToNull = false;
Binders = new ModelBinderDictionary
{
DefaultBinder = this
};
return base.BindModel(controllerContext, bindingContext);
}
开发者ID:JakobLaverdiere,项目名称:StreamusServer,代码行数:12,代码来源:Global.asax.cs
示例19: Register
public override void Register(IContainer container, List<SiteRoute> routes, ViewEngineCollection viewEngines, ModelBinderDictionary modelBinders, ICollection<Asset> globalAssets)
{
RegisterController<MenuController>(container);
RegisterWidget<MenuCustomWidget>(container);
RegisterWidget(container, new CompositeWidget("MenuWidget", "Menu", "MenuWidget")
{
SupportedScopes = SupportedScopes.All,
Description = "This widget will automatically create links to your *visible* collections.",
AreaHints = new[] { "nav" }
});
}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:12,代码来源:MenuPlugin.cs
示例20: MvcConfigModule
public MvcConfigModule(RouteCollection routes,
BundleCollection bundles,
HandlebarsTemplateTransform jsTemplateTransform,
ModelBinderDictionary modelBinders,
GlobalFilterCollection globalFilters)
{
_routes = routes;
_bundles = bundles;
_jsTemplateTransform = jsTemplateTransform;
_modelBinders = modelBinders;
_globalFilters = globalFilters;
}
开发者ID:andycmaj,项目名称:SixDegreesApi,代码行数:12,代码来源:MvcConfigModule.cs
注:本文中的ModelBinderDictionary类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论