Added non-generic registration interface to IKernel and IWindsor to accommodate dynam...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Attributes / ViewComponentDetailsAttribute.cs
blob41606c7eeb8a8452757f8b14ab06588d734127e3
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 /// <summary>
20 /// Identifies the cache strategy associated with a view component
21 /// </summary>
22 public enum ViewComponentCache
24 /// <summary>
25 /// No cache
26 /// </summary>
27 Disabled,
28 /// <summary>
29 /// Always cache the view component output, no varying.
30 /// </summary>
31 Always,
32 /// <summary>
33 /// Uses a custom key generator that should implement the vary algorithm.
34 /// </summary>
35 UseCustomCacheKeyGenerator
38 /// <summary>
39 /// Decorates a <see cref="ViewComponent"/> to associate a custom name with it.
40 /// </summary>
41 /// <remarks>
42 /// Decorates a <see cref="ViewComponent"/> to associate a custom name with it.
43 /// <para>
44 /// Optionally you can associate the section names supported by the
45 /// <see cref="ViewComponent"/>.
46 /// </para>
47 /// </remarks>
48 /// <example>
49 /// In the code below, the class MyHeaderViewConponent will be referenced as just <c>Header</c>,
50 /// and it will support the subsections <c>header</c> and <c>footer</c>.
51 /// <code><![CDATA[
52 /// [ViewComponentDetails("Header", Sections="header,footer")
53 /// public class MyHeaderViewComponent : ViewComponent
54 /// {
55 /// // :
56 /// // :
57 /// }
58 /// ]]>
59 /// </code>
60 /// </example>
61 /// <seealso cref="ViewComponent"/>
62 /// <seealso cref="ViewComponentParamAttribute"/>
63 [AttributeUsage(AttributeTargets.Class), Serializable]
64 public class ViewComponentDetailsAttribute : Attribute
66 private readonly string name;
67 private string sections;
68 private ViewComponentCache cache = ViewComponentCache.Disabled;
69 private Type cacheKeyFactory;
70 private string[] sectionsFromAttribute;
72 /// <summary>
73 /// Initializes a new instance of the <see cref="ViewComponentDetailsAttribute"/> class.
74 /// </summary>
75 /// <param name="name">The specified ViewComponent's Name</param>
76 public ViewComponentDetailsAttribute(String name)
78 this.name = name;
81 /// <summary>
82 /// The component's name
83 /// </summary>
84 public string Name
86 get { return name; }
89 /// <summary>
90 /// Sets the nested sections that this <see cref="ViewComponent"/> supports.
91 /// </summary>
92 /// <value>The nested sections names, comma separated.</value>
93 public string Sections
95 get { return sections; }
96 set
98 sections = value;
99 if (!string.IsNullOrEmpty(sections))
101 sectionsFromAttribute = sections.Split(new char[] {',', ' ', '|'}, StringSplitOptions.RemoveEmptyEntries);
104 if (sectionsFromAttribute == null)
106 sectionsFromAttribute = new string[0];
111 /// <summary>
112 /// Sets the cache strategy.
113 /// </summary>
114 /// <value>The cache.</value>
115 public ViewComponentCache Cache
117 get { return cache; }
118 set { cache = value; }
121 /// <summary>
122 /// Sets the cache key factory.
123 /// </summary>
124 /// <value>The cache key factory.</value>
125 public Type CacheKeyFactory
127 get { return cacheKeyFactory; }
130 if (value != null)
132 cache = ViewComponentCache.UseCustomCacheKeyGenerator;
134 cacheKeyFactory = value;
138 /// <summary>
139 /// Returns true if the section name specified is present on the list of sections.
140 /// </summary>
141 /// <param name="name">The section name.</param>
142 /// <returns></returns>
143 public bool SupportsSection(string name)
145 return Array.FindIndex(sectionsFromAttribute,
146 delegate(string item) { return string.Equals(item, name, StringComparison.InvariantCultureIgnoreCase); }) != -1;