1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
20 /// Decorates a public property in a <see cref="ViewComponent"/>
21 /// to have the framework automatically bind the value using
22 /// the <see cref="ViewComponent.ComponentParams"/> dictionary.
25 /// By default the property name is going to be used as a key to query the params.
27 /// You can also use the <see cref="ViewComponentParamAttribute.Required"/>
28 /// property to define that a parameter is non-optional.
32 /// <para>In the code below, the <c>Text</c> parameter will automatically be bound to the <c>header</c> property.
33 /// If there is no <c>Text</c> parameter, a <see cref="ViewComponentException"/> will be thrown.</para>
34 /// Simailrly, the optional <c>CssClass</c> parameter will be bound to the <c>CssClass</c> property. No error
35 /// occurs if there is no <c>CssClass</c> parameter.
37 /// public class HeaderViewComponent : ViewComponent
39 /// [ViewComponentParam("Text", Required= true)]
40 /// public string header {get; set;}
42 /// [ViewComponentParam]
43 /// public string CssClass {get; set;}
47 /// ]]></code></example>
48 /// <seealso cref="ViewComponent"/>
49 /// <seealso cref="ViewComponentDetailsAttribute"/>
50 [AttributeUsage(AttributeTargets
.Property
, AllowMultiple
= false, Inherited
= true), Serializable
]
51 public class ViewComponentParamAttribute
: Attribute
53 private string paramName
;
54 private bool required
;
55 private object defaultValue
;
58 /// Initializes a new instance of the <see cref="ViewComponentParamAttribute"/> class.
60 public ViewComponentParamAttribute()
65 /// Initializes a new instance of the <see cref="ViewComponentParamAttribute"/> class
66 /// allowing you to override the parameter name to be queried on
67 /// the <see cref="ViewComponent.ComponentParams"/> dictionary.
69 /// <param name="paramName">Overrides the name of the parameter.</param>
70 public ViewComponentParamAttribute(string paramName
)
72 this.paramName
= paramName
;
76 /// Gets or sets a value indicating whether a value for this property is required.
78 /// <value><c>true</c> if required; otherwise, <c>false</c>.</value>
81 get { return required; }
82 set { required = value; }
86 /// Gets the name of the param.
88 /// <value>The name of the param.</value>
89 public string ParamName
91 get { return paramName; }
95 /// Gets or sets the default value for the parameter.
97 /// <value>The default.</value>
100 get { return defaultValue; }
101 set { defaultValue = value; }