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
17 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
\r
18 public sealed class BindAttribute : Attribute {
\r
20 private string _exclude;
\r
21 private string[] _excludeSplit = new string[0];
\r
22 private string _include;
\r
23 private string[] _includeSplit = new string[0];
\r
25 public string Exclude {
\r
27 return _exclude ?? String.Empty;
\r
31 _excludeSplit = AuthorizeAttribute.SplitString(value);
\r
35 public string Include {
\r
37 return _include ?? String.Empty;
\r
41 _includeSplit = AuthorizeAttribute.SplitString(value);
\r
45 public string Prefix {
\r
50 internal static bool IsPropertyAllowed(string propertyName, string[] includeProperties, string[] excludeProperties) {
\r
51 // We allow a property to be bound if its both in the include list AND not in the exclude list.
\r
52 // An empty include list implies all properties are allowed.
\r
53 // An empty exclude list implies no properties are disallowed.
\r
54 bool includeProperty = (includeProperties == null) || (includeProperties.Length == 0) || includeProperties.Contains(propertyName, StringComparer.OrdinalIgnoreCase);
\r
55 bool excludeProperty = (excludeProperties != null) && excludeProperties.Contains(propertyName, StringComparer.OrdinalIgnoreCase);
\r
56 return includeProperty && !excludeProperty;
\r
59 public bool IsPropertyAllowed(string propertyName) {
\r
60 return IsPropertyAllowed(propertyName, _includeSplit, _excludeSplit);
\r