// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Mvc.ModelBinding; namespace Microsoft.AspNet.Mvc { /// /// An attribute that can specify a model name or type of to use for binding. /// [AttributeUsage( // Support method parameters in actions. AttributeTargets.Parameter | // Support properties on model DTOs. AttributeTargets.Property | // Support model types. AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)] public class ModelBinderAttribute : Attribute, IModelNameProvider, IBinderTypeProviderMetadata { private Type _binderType; private BindingSource _bindingSource; /// public Type BinderType { get { return _binderType; } set { if (value != null) { if (!typeof(IModelBinder).IsAssignableFrom(value)) { throw new InvalidOperationException( Resources.FormatBinderType_MustBeIModelBinder( value.FullName, typeof(IModelBinder).FullName)); } } _binderType = value; } } /// public BindingSource BindingSource { get { if (_bindingSource == null && _binderType != null) { return BindingSource.Custom; } return _bindingSource; } set { _bindingSource = value; } } /// public string Name { get; set; } } }