Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Providers / DefaultHelperDescriptorProvider.cs
blobf96ef7d6f298038673929fe7100f4438c33fd3d0
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.Providers
17 using System;
18 using System.Collections;
19 using Castle.Core.Logging;
20 using Castle.MonoRail.Framework.Descriptors;
22 /// <summary>
23 /// Creates <see cref="HelperDescriptor"/> from attributes
24 /// associated with the <see cref="IController"/>
25 /// </summary>
26 public class DefaultHelperDescriptorProvider : IHelperDescriptorProvider
28 /// <summary>
29 /// The logger instance
30 /// </summary>
31 private ILogger logger = NullLogger.Instance;
33 #region IMRServiceEnabled implementation
35 /// <summary>
36 /// Invoked by the framework in order to give a chance to
37 /// obtain other services
38 /// </summary>
39 /// <param name="provider">The service proviver</param>
40 public void Service(IMonoRailServices provider)
42 ILoggerFactory loggerFactory = (ILoggerFactory) provider.GetService(typeof(ILoggerFactory));
44 if (loggerFactory != null)
46 logger = loggerFactory.Create(typeof(DefaultHelperDescriptorProvider));
50 #endregion
52 /// <summary>
53 /// Implementors should collect the helper information
54 /// and return descriptors instances, or an empty array if none
55 /// was found.
56 /// </summary>
57 /// <param name="controllerType">The controller type</param>
58 /// <returns>
59 /// An array of <see cref="HelperDescriptor"/>
60 /// </returns>
61 public HelperDescriptor[] CollectHelpers(Type controllerType)
63 if (logger.IsDebugEnabled)
65 logger.DebugFormat("Collecting helpers for {0}", controllerType);
68 object[] attributes = controllerType.GetCustomAttributes(typeof(IHelperDescriptorBuilder), true);
70 ArrayList descriptors = new ArrayList();
72 foreach(IHelperDescriptorBuilder builder in attributes)
74 HelperDescriptor[] descs = builder.BuildHelperDescriptors();
76 if (logger.IsDebugEnabled)
78 foreach(HelperDescriptor desc in descs)
80 logger.DebugFormat("Collected helper {0} with name {1}", desc.HelperType, desc.Name);
84 descriptors.AddRange(descs);
87 return (HelperDescriptor[]) descriptors.ToArray(typeof(HelperDescriptor));