Remove excessive shortcut key matching in ToolStrip
[mono.git] / mcs / class / System.Web.Mvc / System.Web.Mvc / ModelBinderAttribute.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System;\r
15     using System.Globalization;\r
16     using System.Web.Mvc.Resources;\r
17 \r
18     [AttributeUsage(ValidTargets, AllowMultiple = false, Inherited = false)]\r
19     public sealed class ModelBinderAttribute : CustomModelBinderAttribute {\r
20 \r
21         public ModelBinderAttribute(Type binderType) {\r
22             if (binderType == null) {\r
23                 throw new ArgumentNullException("binderType");\r
24             }\r
25             if (!typeof(IModelBinder).IsAssignableFrom(binderType)) {\r
26                 string message = String.Format(CultureInfo.CurrentUICulture,\r
27                     MvcResources.ModelBinderAttribute_TypeNotIModelBinder, binderType.FullName);\r
28                 throw new ArgumentException(message, "binderType");\r
29             }\r
30 \r
31             BinderType = binderType;\r
32         }\r
33 \r
34         public Type BinderType {\r
35             get;\r
36             private set;\r
37         }\r
38 \r
39         public override IModelBinder GetBinder() {\r
40             try {\r
41                 return (IModelBinder)Activator.CreateInstance(BinderType);\r
42             }\r
43             catch (Exception ex) {\r
44                 throw new InvalidOperationException(\r
45                     String.Format(\r
46                         CultureInfo.CurrentUICulture,\r
47                         MvcResources.ModelBinderAttribute_ErrorCreatingModelBinder,\r
48                         BinderType.FullName),\r
49                     ex);\r
50             }\r
51         }\r
52 \r
53     }\r
54 }\r