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
18 using Castle
.MonoRail
.Framework
.Descriptors
;
21 /// Associates a helper class with the controller.
23 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=true), Serializable
]
24 public class HelperAttribute
: Attribute
, IHelperDescriptorBuilder
26 private readonly Type helperType
;
27 private readonly String name
;
30 /// Constructs a <see cref="HelperAttribute"/>
31 /// with the supplied <c>helperType</c>.
33 /// <param name="helperType">The helper type</param>
34 public HelperAttribute(Type helperType
) : this(helperType
, null)
39 /// Constructs a <see cref="HelperAttribute"/>
40 /// with the supplied <c>helperType</c> and a name to be bound to it.
42 /// <param name="helperType">The helper type</param>
43 /// <param name="name">Name bound to the helper. The name will be
44 /// used on the view to gain access to it</param>
45 public HelperAttribute(Type helperType
, String name
)
47 this.helperType
= helperType
;
48 this.name
= (name
== null || name
.Trim() == String
.Empty
) ? helperType
.Name
: name
;
52 /// Gets Name bound to the helper. The name will be
53 /// used on the view to gain access to it
61 /// Gets the helper type
63 public Type HelperType
65 get { return helperType; }
69 /// <see cref="IHelperDescriptorBuilder"/> implementation.
70 /// Gets the <seealso cref="HelperDescriptor"/>
71 /// that describes the helper.
73 /// <returns>The descriptor instance</returns>
74 public HelperDescriptor
[] BuildHelperDescriptors()
76 return new HelperDescriptor
[] { new HelperDescriptor(helperType, name) }
;