Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Services / Utils / ControllerInspectionUtil.cs
blob0419aff68243573b53c497f0a26906073380c10f
1 // Copyright 2004-2008 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.Services.Utils
17 using System;
18 using Castle.MonoRail.Framework.Descriptors;
20 /// <summary>
21 /// Utilities methods to inspect the controller Type
22 /// and gathers its name and area.
23 /// </summary>
24 public static class ControllerInspectionUtil
26 /// <summary>
27 /// Creates a <see cref="ControllerDescriptor"/> based on the conventions
28 /// and possible attributes found for the Controller Type specified
29 /// </summary>
30 /// <param name="controllerType">The controller type</param>
31 /// <returns>A controller descriptor</returns>
32 public static ControllerDescriptor Inspect(Type controllerType)
34 ControllerDescriptor descriptor;
36 if (controllerType.IsDefined(typeof(ControllerDetailsAttribute), true))
38 object[] attrs = controllerType.GetCustomAttributes(
39 typeof(ControllerDetailsAttribute), true);
41 ControllerDetailsAttribute details = (ControllerDetailsAttribute) attrs[0];
43 descriptor = new ControllerDescriptor(controllerType,
44 ObtainControllerName(details.Name, controllerType),
45 details.Area, details.Sessionless);
47 else
49 descriptor = new ControllerDescriptor(controllerType,
50 ObtainControllerName(null, controllerType), String.Empty, false);
53 return descriptor;
56 /// <summary>
57 /// Obtains the name of the controller.
58 /// </summary>
59 /// <param name="name">The name.</param>
60 /// <param name="controller">The controller.</param>
61 /// <returns></returns>
62 private static String ObtainControllerName(String name, Type controller)
64 if (name == null || name.Length == 0)
66 return Strip(controller.Name);
68 return name;
71 /// <summary>
72 /// Strips the specified name.
73 /// </summary>
74 /// <param name="name">The name.</param>
75 /// <returns></returns>
76 private static String Strip(String name)
78 if (name.EndsWith("Controller"))
80 return name.Substring(0, name.IndexOf("Controller"));
82 return name;