1 namespace System.Web.Mvc {
5 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
6 public sealed class BindAttribute : Attribute {
8 private string _exclude;
9 private string[] _excludeSplit = new string[0];
10 private string _include;
11 private string[] _includeSplit = new string[0];
13 public string Exclude {
15 return _exclude ?? String.Empty;
19 _excludeSplit = AuthorizeAttribute.SplitString(value);
23 public string Include {
25 return _include ?? String.Empty;
29 _includeSplit = AuthorizeAttribute.SplitString(value);
33 public string Prefix {
38 internal static bool IsPropertyAllowed(string propertyName, string[] includeProperties, string[] excludeProperties) {
39 // We allow a property to be bound if its both in the include list AND not in the exclude list.
40 // An empty include list implies all properties are allowed.
41 // An empty exclude list implies no properties are disallowed.
42 bool includeProperty = (includeProperties == null) || (includeProperties.Length == 0) || includeProperties.Contains(propertyName, StringComparer.OrdinalIgnoreCase);
43 bool excludeProperty = (excludeProperties != null) && excludeProperties.Contains(propertyName, StringComparer.OrdinalIgnoreCase);
44 return includeProperty && !excludeProperty;
47 public bool IsPropertyAllowed(string propertyName) {
48 return IsPropertyAllowed(propertyName, _includeSplit, _excludeSplit);