Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / mcs / class / System.Web.Mvc3 / Mvc / BindAttribute.cs
1 namespace System.Web.Mvc {
2     using System;
3     using System.Linq;
4
5     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
6     public sealed class BindAttribute : Attribute {
7
8         private string _exclude;
9         private string[] _excludeSplit = new string[0];
10         private string _include;
11         private string[] _includeSplit = new string[0];
12
13         public string Exclude {
14             get {
15                 return _exclude ?? String.Empty;
16             }
17             set {
18                 _exclude = value;
19                 _excludeSplit = AuthorizeAttribute.SplitString(value);
20             }
21         }
22
23         public string Include {
24             get {
25                 return _include ?? String.Empty;
26             }
27             set {
28                 _include = value;
29                 _includeSplit = AuthorizeAttribute.SplitString(value);
30             }
31         }
32
33         public string Prefix {
34             get;
35             set;
36         }
37
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;
45         }
46
47         public bool IsPropertyAllowed(string propertyName) {
48             return IsPropertyAllowed(propertyName, _includeSplit, _excludeSplit);
49         }
50     }
51 }