// 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 { [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class BindPropertyAttribute : Attribute, IModelNameProvider, IBinderTypeProviderMetadata, IRequestPredicateProvider { private static readonly Func _supportsAllRequests = (c) => true; private static readonly Func _supportsNonGetRequests = IsNonGetRequest; private BindingSource _bindingSource; public bool SupportsGet { get; set; } 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; } Func IRequestPredicateProvider.RequestPredicate { get { return SupportsGet ? _supportsAllRequests : _supportsNonGetRequests; } } private static bool IsNonGetRequest(ActionContext context) { return !string.Equals(context.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase); } } }