Added non-generic registration interface to IKernel and IWindsor to accommodate dynam...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Attributes / FilterAttribute.cs
blobc1c4bffb0b6e2d997d36f9a60cd2010f3c14ebaf
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 /// Decorates a controller associating a <see cref="IFilter"/>
22 /// implementation with it. More than one can be associated.
23 /// </summary>
24 /// <remarks>
25 /// If more than one filter is associate with an action (or controller and
26 /// action), the order of execution cannot be predicted. In this case
27 /// use <see cref="ExecutionOrder"/> to define the order of execution.
28 /// </remarks>
29 [AttributeUsage(AttributeTargets.Class, AllowMultiple=true, Inherited=true), Serializable]
30 public class FilterAttribute : Attribute, IFilterDescriptorBuilder
32 private readonly Type filterType;
33 private readonly ExecuteEnum when;
34 private int executionOrder = Int32.MaxValue;
36 /// <summary>
37 /// Constructs a FilterAttribute associating
38 /// the filter type and when the filter should be invoked.
39 /// </summary>
40 /// <param name="when">When to execute the filter</param>
41 /// <param name="filterType">The filter implementation</param>
42 public FilterAttribute(ExecuteEnum when, Type filterType)
44 if (!typeof(IFilter).IsAssignableFrom(filterType))
46 throw new ArgumentException("The specified type does not implement IFilter");
49 this.filterType = filterType;
50 this.when = when;
53 /// <summary>
54 /// Gets the filter implementation type
55 /// </summary>
56 public Type FilterType
58 get { return filterType; }
61 /// <summary>
62 /// Gets when to run the filter
63 /// </summary>
64 public ExecuteEnum When
66 get { return when; }
69 /// <summary>
70 /// Gets or sets the filter execution order.
71 /// The lower the value, the higher the priority
72 /// </summary>
73 public int ExecutionOrder
75 get { return executionOrder; }
76 set { executionOrder = value; }
79 /// <summary>
80 /// Implementation of <see cref="IFilterDescriptorBuilder"/>.
81 /// Returns the descriptor for this filter association.
82 /// </summary>
83 /// <returns></returns>
84 public FilterDescriptor[] BuildFilterDescriptors()
86 return new FilterDescriptor[] { new FilterDescriptor(FilterType, when, executionOrder, this) };