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 layout name with a controller.
22 /// The layout can later be changed using the LayoutName
23 /// property of the <see cref="IController"/>.
25 [AttributeUsage(AttributeTargets
.Class
| AttributeTargets
.Method
, AllowMultiple
=false), Serializable
]
26 public class LayoutAttribute
: Attribute
, ILayoutDescriptorBuilder
28 private readonly string[] layoutNames
;
31 /// Constructs a LayoutAttribute with the
34 public LayoutAttribute(string layoutName
)
36 if (string.IsNullOrEmpty(layoutName
))
38 throw new ArgumentNullException("layoutName", "Invalid layout name");
41 layoutNames
= new string[] { layoutName }
;
45 /// Constructs a LayoutAttribute with the
48 public LayoutAttribute(params string[] layoutNames
)
50 if (layoutNames
.Length
== 0)
52 throw new ArgumentNullException("layoutNames", "Invalid layout name");
55 this.layoutNames
= layoutNames
;
59 /// Gets the layout name
61 public String LayoutName
63 get { return layoutNames[0]; }
67 /// <see cref="ILayoutDescriptorBuilder"/> implementation.
68 /// Gets the descriptor that describes the layout.
70 public LayoutDescriptor
BuildLayoutDescriptor()
72 return new LayoutDescriptor(layoutNames
);