// Copyright (c) .NET Foundation. 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.AspNetCore.Mvc.ModelBinding; namespace Microsoft.AspNetCore.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 BindingSource _bindingSource; /// /// Initializes a new instance of . /// public ModelBinderAttribute() { } /// /// Initializes a new instance of . /// /// A which implements . public ModelBinderAttribute(Type binderType) { if (binderType == null) { throw new ArgumentNullException(nameof(binderType)); } BinderType = binderType; } /// public Type BinderType { get; set; } /// public virtual BindingSource BindingSource { get { if (_bindingSource == null && BinderType != null) { return BindingSource.Custom; } return _bindingSource; } protected set { _bindingSource = value; } } /// public string Name { get; set; } } }