Added non-generic registration interface to IKernel and IWindsor to accommodate dynam...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Attributes / HelperAttribute.cs
blob30ff977b595ce83e01cf66ce12b351510dc29ad0
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;
18 using Castle.MonoRail.Framework.Descriptors;
20 /// <summary>
21 /// Associates a helper class with the controller.
22 /// </summary>
23 [AttributeUsage(AttributeTargets.Class, AllowMultiple=true), Serializable]
24 public class HelperAttribute : Attribute, IHelperDescriptorBuilder
26 private readonly Type helperType;
27 private readonly String name;
29 /// <summary>
30 /// Constructs a <see cref="HelperAttribute"/>
31 /// with the supplied <c>helperType</c>.
32 /// </summary>
33 /// <param name="helperType">The helper type</param>
34 public HelperAttribute(Type helperType) : this(helperType, null)
38 /// <summary>
39 /// Constructs a <see cref="HelperAttribute"/>
40 /// with the supplied <c>helperType</c> and a name to be bound to it.
41 /// </summary>
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;
51 /// <summary>
52 /// Gets Name bound to the helper. The name will be
53 /// used on the view to gain access to it
54 /// </summary>
55 public String Name
57 get { return name; }
60 /// <summary>
61 /// Gets the helper type
62 /// </summary>
63 public Type HelperType
65 get { return helperType; }
68 /// <summary>
69 /// <see cref="IHelperDescriptorBuilder"/> implementation.
70 /// Gets the <seealso cref="HelperDescriptor"/>
71 /// that describes the helper.
72 /// </summary>
73 /// <returns>The descriptor instance</returns>
74 public HelperDescriptor[] BuildHelperDescriptors()
76 return new HelperDescriptor[] { new HelperDescriptor(helperType, name) };