Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / Attributes / HelperAttribute.cs
blobab967e824c1e878d042ec5c7c2a602781978e4a0
1 // Copyright 2004-2007 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 using Castle.MonoRail.Framework.Internal;
21 /// <summary>
22 /// Associates a helper class with the controller.
23 /// </summary>
24 [AttributeUsage(AttributeTargets.Class, AllowMultiple=true), Serializable]
25 public class HelperAttribute : Attribute, IHelperDescriptorBuilder
27 private readonly Type helperType;
28 private readonly String name;
30 /// <summary>
31 /// Constructs a <see cref="HelperAttribute"/>
32 /// with the supplied <c>helperType</c>.
33 /// </summary>
34 /// <param name="helperType">The helper type</param>
35 public HelperAttribute(Type helperType) : this(helperType, null)
39 /// <summary>
40 /// Constructs a <see cref="HelperAttribute"/>
41 /// with the supplied <c>helperType</c> and a name to be bound to it.
42 /// </summary>
43 /// <param name="helperType">The helper type</param>
44 /// <param name="name">Name bound to the helper. The name will be
45 /// used on the view to gain access to it</param>
46 public HelperAttribute(Type helperType, String name)
48 this.helperType = helperType;
49 this.name = (name == null || name.Trim() == String.Empty) ? helperType.Name : name;
52 /// <summary>
53 /// Gets Name bound to the helper. The name will be
54 /// used on the view to gain access to it
55 /// </summary>
56 public String Name
58 get { return name; }
61 /// <summary>
62 /// Gets the helper type
63 /// </summary>
64 public Type HelperType
66 get { return helperType; }
69 /// <summary>
70 /// <see cref="IHelperDescriptorBuilder"/> implementation.
71 /// Gets the <seealso cref="HelperDescriptor"/>
72 /// that describes the helper.
73 /// </summary>
74 /// <returns>The descriptor instance</returns>
75 public HelperDescriptor[] BuildHelperDescriptors()
77 return new HelperDescriptor[] { new HelperDescriptor(helperType, name) };