Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Attributes / ViewComponentParamAttribute.cs
blob1cad6b2412d963b392745dfb422256704e088037
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
19 /// <summary>
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.
23 /// </summary>
24 /// <remarks>
25 /// By default the property name is going to be used as a key to query the params.
26 /// <para>
27 /// You can also use the <see cref="ViewComponentParamAttribute.Required"/>
28 /// property to define that a parameter is non-optional.
29 /// </para>
30 /// </remarks>
31 /// <example>
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.
36 /// <code><![CDATA[
37 /// public class HeaderViewComponent : ViewComponent
38 /// {
39 /// [ViewComponentParam("Text", Required= true)]
40 /// public string header {get; set;}
41 ///
42 /// [ViewComponentParam]
43 /// public string CssClass {get; set;}
44 /// // :
45 /// // :
46 /// }
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;
57 /// <summary>
58 /// Initializes a new instance of the <see cref="ViewComponentParamAttribute"/> class.
59 /// </summary>
60 public ViewComponentParamAttribute()
64 /// <summary>
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.
68 /// </summary>
69 /// <param name="paramName">Overrides the name of the parameter.</param>
70 public ViewComponentParamAttribute(string paramName)
72 this.paramName = paramName;
75 /// <summary>
76 /// Gets or sets a value indicating whether a value for this property is required.
77 /// </summary>
78 /// <value><c>true</c> if required; otherwise, <c>false</c>.</value>
79 public bool Required
81 get { return required; }
82 set { required = value; }
85 /// <summary>
86 /// Gets the name of the param.
87 /// </summary>
88 /// <value>The name of the param.</value>
89 public string ParamName
91 get { return paramName; }
94 /// <summary>
95 /// Gets or sets the default value for the parameter.
96 /// </summary>
97 /// <value>The default.</value>
98 public object Default
100 get { return defaultValue; }
101 set { defaultValue = value; }