Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Core / Castle.Core / Model / Configuration / Xml / XmlConfigurationDeserializer.cs
blobc29e48c727f45246a4a0cf05dde6169d7c7c2ce8
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.Core.Configuration.Xml
17 using System;
18 using System.Text;
19 using System.Xml;
21 /// <summary>
22 /// Pendent
23 /// </summary>
24 public class XmlConfigurationDeserializer
26 /// <summary>
27 /// Deserializes the specified node into an abstract representation of configuration.
28 /// </summary>
29 /// <param name="node">The node.</param>
30 /// <returns></returns>
31 public IConfiguration Deserialize(XmlNode node)
33 return Deserialize(node);
36 public static IConfiguration GetDeserializedNode(XmlNode node)
38 MutableConfiguration config;
39 ConfigurationCollection configChilds = new ConfigurationCollection();
41 StringBuilder configValue = new StringBuilder();
43 if (node.HasChildNodes)
45 foreach(XmlNode child in node.ChildNodes)
47 if (IsTextNode(child))
49 configValue.Append(child.Value);
51 else if (child.NodeType == XmlNodeType.Element)
53 configChilds.Add(GetDeserializedNode(child));
58 config = new MutableConfiguration(node.Name, GetConfigValue(configValue.ToString()));
60 foreach(XmlAttribute attribute in node.Attributes)
62 config.Attributes.Add(attribute.Name, attribute.Value);
65 config.Children.AddRange(configChilds);
67 return config;
70 /// <summary>
71 /// If a config value is an empty string we return null, this is to keep
72 /// backward compability with old code
73 /// </summary>
74 public static string GetConfigValue(string value)
76 value = value.Trim();
78 return value == String.Empty ? null : value;
81 public static bool IsTextNode(XmlNode node)
83 return node.NodeType == XmlNodeType.Text || node.NodeType == XmlNodeType.CDATA;