New tests.
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / ReflectedParameterBindingInfo.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\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
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System;\r
15     using System.Collections.Generic;\r
16     using System.Collections.ObjectModel;\r
17     using System.Globalization;\r
18     using System.Reflection;\r
19     using System.Web.Mvc.Resources;\r
20 \r
21     internal class ReflectedParameterBindingInfo : ParameterBindingInfo {\r
22 \r
23         private ICollection<string> _exclude = new string[0];\r
24         private ICollection<string> _include = new string[0];\r
25         private readonly ParameterInfo _parameterInfo;\r
26         private string _prefix;\r
27 \r
28         public ReflectedParameterBindingInfo(ParameterInfo parameterInfo) {\r
29             _parameterInfo = parameterInfo;\r
30             ReadSettingsFromBindAttribute();\r
31         }\r
32 \r
33         public override IModelBinder Binder {\r
34             get {\r
35                 IModelBinder binder = ModelBinders.GetBinderFromAttributes(_parameterInfo,\r
36                     () => String.Format(CultureInfo.CurrentUICulture, MvcResources.ReflectedParameterBindingInfo_MultipleConverterAttributes,\r
37                         _parameterInfo.Name, _parameterInfo.Member));\r
38 \r
39                 return binder;\r
40             }\r
41         }\r
42 \r
43         public override ICollection<string> Exclude {\r
44             get {\r
45                 return _exclude;\r
46             }\r
47         }\r
48 \r
49         public override ICollection<string> Include {\r
50             get {\r
51                 return _include;\r
52             }\r
53         }\r
54 \r
55         public override string Prefix {\r
56             get {\r
57                 return _prefix;\r
58             }\r
59         }\r
60 \r
61         private void ReadSettingsFromBindAttribute() {\r
62             BindAttribute attr = (BindAttribute)Attribute.GetCustomAttribute(_parameterInfo, typeof(BindAttribute));\r
63             if (attr == null) {\r
64                 return;\r
65             }\r
66 \r
67             _exclude = new ReadOnlyCollection<string>(AuthorizeAttribute.SplitString(attr.Exclude));\r
68             _include = new ReadOnlyCollection<string>(AuthorizeAttribute.SplitString(attr.Include));\r
69             _prefix = attr.Prefix;\r
70         }\r
71 \r
72     }\r
73 }\r