Fixing an issue with output parameters that are of type IntPtr
[castle.git] / InversionOfControl / Castle.Windsor / Configuration / Interpreters / XmlProcessor / ElementProcessors / PropertiesElementProcessor.cs
blob34040b6ff6faa183c0418840e7f69e44cba3a6de
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.Windsor.Configuration.Interpreters.XmlProcessor.ElementProcessors
17 using System;
18 using System.Xml;
20 public class PropertiesElementProcessor : AbstractXmlNodeProcessor
22 public override String Name
24 get { return "properties"; }
27 /// <summary>
28 ///
29 /// </summary>
30 /// <param name="nodeList"></param>
31 /// <param name="engine"></param>
32 /// <example>
33 /// <code>
34 /// <properties>
35 /// <attributes>
36 /// <myAttribute>attributeValue</myAttribute>
37 /// </attributes>
38 /// <myProperty>propertyValue</myProperty>
39 /// </properties>
40 /// </code>
41 /// </example>
42 public override void Process(IXmlProcessorNodeList nodeList, IXmlProcessorEngine engine)
44 XmlElement element = nodeList.Current as XmlElement;
46 IXmlProcessorNodeList childNodes = new DefaultXmlProcessorNodeList(element.ChildNodes);
48 while(childNodes.MoveNext())
50 // Properties processing its a little more complicated than usual
51 // since we need to support all special tags (if,else,define...)
52 // plus we need to register any regular element as a property asap
53 // since we should support properties that reference other properties
54 // i.e. <myprop2>#{prop1}</myprop2>
55 if (engine.HasSpecialProcessor(childNodes.Current))
57 // Current node its a special element so we bookmark it before processing it...
58 XmlNode current = childNodes.Current;
60 int pos = childNodes.CurrentPosition;
62 engine.DispatchProcessCurrent(childNodes);
64 // ...after processing we need to refresh childNodes
65 // to account for any special element that affects the node tree (if,choose...)
66 childNodes = new DefaultXmlProcessorNodeList(element.ChildNodes);
68 // we only care about changes in the tree from the current node and forward
69 // so if the new list is empty or smaller we just exit the loop
70 if (pos < childNodes.Count)
72 childNodes.CurrentPosition = pos;
74 // if the current node gets replaced in the new list we need to restart processing
75 // otherwise we just continue as usual
76 if (childNodes.Current != current)
78 childNodes.CurrentPosition -= 1;
79 continue;
82 else
84 break;
87 else
89 engine.DispatchProcessCurrent(childNodes);
92 if (IgnoreNode(childNodes.Current)) continue;
94 XmlElement elem = GetNodeAsElement(element, childNodes.Current);
96 engine.AddProperty(elem);
99 RemoveItSelf(element);