forked from MRCollective/ChameleonForms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppStart.cs.pp
26 lines (24 loc) · 1.12 KB
/
AppStart.cs.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using ChameleonForms.Attributes;
using ChameleonForms.ModelBinders;
using System;
using System.Linq;
using System.Web.Mvc;
[assembly: WebActivator.PreApplicationStartMethod(typeof($rootnamespace$.RegisterChameleonFormsComponents), "Start")]
namespace $rootnamespace$
{
public static class RegisterChameleonFormsComponents
{
public static void Start()
{
ModelBinders.Binders.Add(typeof(DateTime), new DateTimeModelBinder());
ModelBinders.Binders.Add(typeof(DateTime?), new DateTimeModelBinder());
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RequiredFlagsEnumAttribute), typeof(RequiredAttributeAdapter));
typeof(RegisterChameleonFormsComponents).Assembly.GetTypes().Where(t => t.IsEnum && t.GetCustomAttributes(typeof(FlagsAttribute), false).Any())
.ToList().ForEach(t =>
{
ModelBinders.Binders.Add(t, new FlagsEnumModelBinder());
ModelBinders.Binders.Add(typeof(Nullable<>).MakeGenericType(t), new FlagsEnumModelBinder());
});
}
}
}