1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\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
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
15 using System.Globalization;
\r
16 using System.Web.Mvc.Resources;
\r
18 [AttributeUsage(ValidTargets, AllowMultiple = false, Inherited = false)]
\r
19 public sealed class ModelBinderAttribute : CustomModelBinderAttribute {
\r
21 public ModelBinderAttribute(Type binderType) {
\r
22 if (binderType == null) {
\r
23 throw new ArgumentNullException("binderType");
\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
31 BinderType = binderType;
\r
34 public Type BinderType {
\r
39 public override IModelBinder GetBinder() {
\r
41 return (IModelBinder)Activator.CreateInstance(BinderType);
\r
43 catch (Exception ex) {
\r
44 throw new InvalidOperationException(
\r
46 CultureInfo.CurrentUICulture,
\r
47 MvcResources.ModelBinderAttribute_ErrorCreatingModelBinder,
\r
48 BinderType.FullName),
\r