Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework.Views.NVelocity / CustomDirectives / SubSectionDirective.cs
blob3aea36d5e6e8e72c8086f5d1c45f2b19187787a0
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 using Directive = NVelocity.Runtime.Directive.Directive;
16 using DirectiveType = NVelocity.Runtime.Directive.DirectiveType;
17 using IInternalContextAdapter = NVelocity.Context.IInternalContextAdapter;
18 using INode = NVelocity.Runtime.Parser.Node.INode;
19 using IRuntimeServices = NVelocity.Runtime.IRuntimeServices;
21 namespace Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives
23 using System;
24 using System.IO;
26 public class SubSectionDirective : Directive
28 private readonly string name;
29 private NVelocityViewContextAdapter contextAdapter;
30 private INode savedNode;
32 public SubSectionDirective(String name)
34 this.name = name;
37 /// <summary>
38 /// Return the name of this directive
39 /// </summary>
40 public override String Name
42 get { return name; }
43 set { throw new NotImplementedException(); }
46 /// <summary>
47 /// Get the directive type BLOCK/LINE
48 /// </summary>
49 public override DirectiveType Type
51 get { return DirectiveType.BLOCK; }
54 public override bool AcceptParams
56 get { return false; }
59 /// <summary>
60 /// How this directive is to be initialized.
61 /// </summary>
62 public override void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node)
64 base.Init(rs, context, node);
66 savedNode = node;
69 /// <summary>
70 /// How this directive is to be rendered
71 /// </summary>
72 public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
74 if (context == null)
76 throw new MonoRailException("context is null");
79 if (contextAdapter == null)
81 throw new MonoRailException("contextAdapter is null");
84 if (contextAdapter.ContextVars == null)
86 throw new MonoRailException("contextAdapter.ContextVars is null");
89 // foreach(DictionaryEntry entry in contextAdapter.ContextVars)
90 // {
91 // context.Put(entry.Key.ToString(), entry.Value);
92 // }
94 for(int i=0; i < savedNode.ChildrenCount; i++)
96 INode childNode = savedNode.GetChild(i);
97 childNode.Render(context, writer);
100 return true;
103 internal NVelocityViewContextAdapter ContextAdapter
105 set { contextAdapter = value; }