Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Configuration / ControllersConfig.cs
blobd56f0ddf42b32775ac71b21274628a743fde0938
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.Configuration
17 using System;
18 using System.Collections.Generic;
19 using System.Configuration;
20 using System.Reflection;
21 using System.Xml;
23 /// <summary>
24 /// Represents the controller node configuration
25 /// </summary>
26 public class ControllersConfig : ISerializedConfig
28 private readonly List<string> assemblies = new List<string>();
29 private Type customControllerFactory;
31 /// <summary>
32 /// Initializes a new instance of the <see cref="ControllersConfig"/> class.
33 /// </summary>
34 public ControllersConfig()
38 #region ISerializedConfig implementation
40 /// <summary>
41 /// Deserializes the specified section.
42 /// </summary>
43 /// <param name="section">The section.</param>
44 public void Deserialize(XmlNode section)
46 XmlNode customFactoryNode = section.SelectSingleNode("customControllerFactory");
48 if (customFactoryNode != null)
50 XmlAttribute typeAtt = customFactoryNode.Attributes["type"];
52 if (typeAtt == null || typeAtt.Value == String.Empty)
54 String message = "If the node customControllerFactory is " +
55 "present, you must specify the 'type' attribute";
56 throw new ConfigurationErrorsException(message);
59 String typeName = typeAtt.Value;
61 customControllerFactory = TypeLoadUtil.GetType(typeName);
64 XmlNodeList nodeList = section.SelectNodes("controllers/assembly");
66 foreach(XmlNode node in nodeList)
68 assemblies.Add(node.ChildNodes[0].Value);
72 #endregion
74 /// <summary>
75 /// Adds an assembly that should be source of controllers.
76 /// </summary>
77 /// <param name="assembly">The assembly.</param>
78 public void AddAssembly(Assembly assembly)
80 if (assembly == null) throw new ArgumentNullException("assembly");
82 assemblies.Add(assembly.FullName);
85 /// <summary>
86 /// Adds an assembly that should be source of controllers.
87 /// </summary>
88 /// <param name="assemblyName">Name of the assembly.</param>
89 public void AddAssembly(string assemblyName)
91 if (assemblyName == null) throw new ArgumentNullException("assemblyName");
93 assemblies.Add(assemblyName);
96 /// <summary>
97 /// Gets or sets the assemblies.
98 /// </summary>
99 /// <value>The assemblies.</value>
100 public List<string> Assemblies
102 get { return assemblies; }
105 /// <summary>
106 /// Gets or sets the custom controller factory.
107 /// </summary>
108 /// <seealso cref="IControllerFactory"/>
109 /// <value>The custom controller factory.</value>
110 public Type CustomControllerFactory
112 get { return customControllerFactory; }
113 set { customControllerFactory = value; }