Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/System.Web.Mvc/ModelBinderAttribute.cs')
-rw-r--r--src/System.Web.Mvc/ModelBinderAttribute.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/System.Web.Mvc/ModelBinderAttribute.cs b/src/System.Web.Mvc/ModelBinderAttribute.cs
new file mode 100644
index 00000000..4e517d3c
--- /dev/null
+++ b/src/System.Web.Mvc/ModelBinderAttribute.cs
@@ -0,0 +1,44 @@
+using System.Globalization;
+using System.Web.Mvc.Properties;
+
+namespace System.Web.Mvc
+{
+ [AttributeUsage(ValidTargets, AllowMultiple = false, Inherited = false)]
+ public sealed class ModelBinderAttribute : CustomModelBinderAttribute
+ {
+ public ModelBinderAttribute(Type binderType)
+ {
+ if (binderType == null)
+ {
+ throw new ArgumentNullException("binderType");
+ }
+ if (!typeof(IModelBinder).IsAssignableFrom(binderType))
+ {
+ string message = String.Format(CultureInfo.CurrentCulture,
+ MvcResources.ModelBinderAttribute_TypeNotIModelBinder, binderType.FullName);
+ throw new ArgumentException(message, "binderType");
+ }
+
+ BinderType = binderType;
+ }
+
+ public Type BinderType { get; private set; }
+
+ public override IModelBinder GetBinder()
+ {
+ try
+ {
+ return (IModelBinder)Activator.CreateInstance(BinderType);
+ }
+ catch (Exception ex)
+ {
+ throw new InvalidOperationException(
+ String.Format(
+ CultureInfo.CurrentCulture,
+ MvcResources.ModelBinderAttribute_ErrorCreatingModelBinder,
+ BinderType.FullName),
+ ex);
+ }
+ }
+ }
+}