当前位置: 首页>>代码示例>>C#>>正文


C# INode.GetChild方法代码示例

本文整理汇总了C#中INode.GetChild方法的典型用法代码示例。如果您正苦于以下问题:C# INode.GetChild方法的具体用法?C# INode.GetChild怎么用?C# INode.GetChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在INode的用法示例。


在下文中一共展示了INode.GetChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Render

		public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
		{
			if (node.ChildrenCount != 2)
			{
				throw new MonoRailException("#capturefor directive expects an id attribute and a template block");
			}

			var idNode = (ASTWord) node.GetChild(0);
			var bodyNode = (ASTBlock) node.GetChild(1);

			var id = idNode.Literal;

			var buffer = new StringWriter();
			var sb = buffer.GetStringBuilder();

			bodyNode.Render(context, buffer);

			var currentContent = context[id] as string;

			if( currentContent != null )
			{
				sb.Append(currentContent);
			}

			context[id] = sb.ToString();

			return true;
		}
开发者ID:smoothdeveloper,项目名称:Castle.MonoRail,代码行数:28,代码来源:CaptureForDirective.cs

示例2: Render

        public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
        {
            if(node.ChildrenCount == 2) {
                string lang = node.GetChild(0).Value(context) as string;
                var codeWriter = new StringWriter();
                node.GetChild(1).Render(context, codeWriter);
                var code = codeWriter.ToString();

                if(lang != null && !string.IsNullOrEmpty(code)) {
                    var highlighter = new SyntaxHighlighter();
                    writer.WriteLine("<div class=\"syntax\"><div class=\"code\">");
                    writer.Write(highlighter.Highlight(code, lang));
                    writer.WriteLine("</div></div>");
                }
            }

            return true;
        }
开发者ID:JeremySkinner,项目名称:Staticity,代码行数:18,代码来源:CodeDirective.cs

示例3: Init

		public override void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node)
		{
			base.Init(rs, context, node);

			compNameNode = node.GetChild(0);

			if (compNameNode == null)
			{
				String message = String.Format("You must specify the component name on the #{0} directive", Name);
				throw new ViewComponentException(message);
			}
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:12,代码来源:AbstractComponentDirective.cs

示例4: GetIterator

        /// <summary>
        /// returns an Iterator to the collection in the #foreach()
        /// </summary>
        /// <param name="context"> current context </param>
        /// <param name="node">  AST node </param>
        /// <returns>Iterator to do the dataset </returns>
        private IEnumerator GetIterator(IInternalContextAdapter context, INode node)
        {
            // get our list object, and punt if it's null.
            Object listObject = node.GetChild(2).Value(context);

            // if we have an event cartridge, get a new value object
            NVelocity.App.Events.EventCartridge eventCartridge = context.EventCartridge;
            if (eventCartridge != null)
            {
                listObject = eventCartridge.ReferenceInsert(new Stack(), node.GetChild(2).Literal, listObject);
            }

            if (listObject == null)
            {
                return null;
            }

            // See if we already know what type this is. 
            // Use the introspection cache
            EnumType type = EnumType.Unknown;

            IntrospectionCacheData introspectionCacheData = context.ICacheGet(this);
            Type c = listObject.GetType();

            // if we have an entry in the cache, and the Class we have
            // cached is the same as the Class of the data object
            // then we are ok

            if (introspectionCacheData != null && introspectionCacheData.ContextData == c)
            {
                // dig the type out of the data object
                type = ((EnumType)introspectionCacheData.Thingy);
            }

            // If we still don't know what this is, 
            // figure out what type of object the list
            // element is, and get the iterator for it
            if (type == EnumType.Unknown)
            {
                if (listObject.GetType().IsArray)
                {
                    type = EnumType.Array;
                }
                else if (listObject is IDictionary)
                {
                    type = EnumType.Dictionary;
                }
                else if (listObject is ICollection)
                {
                    type = EnumType.Collection;
                }
                else if (listObject is IEnumerable)
                {
                    type = EnumType.Enumerable;
                }
                else if (listObject is IEnumerator)
                {
                    type = EnumType.Enumeration;
                }

                // if we did figure it out, cache it
                if (type != EnumType.Unknown)
                {
                    introspectionCacheData = new IntrospectionCacheData(c, type);
                    context.ICachePut(this, introspectionCacheData);
                }
            }

            // now based on the type from either cache or examination...
            switch (type)
            {
                case EnumType.Collection:
                    return ((ICollection)listObject).GetEnumerator();

                case EnumType.Enumerable:
                    return ((IEnumerable)listObject).GetEnumerator();

                case EnumType.Enumeration:
                    runtimeServices.Warn(
                        string.Format(
                            "Warning! The reference {0} is an Enumeration in the #foreach() loop at [{1},{2}] in template {3}. Because it's not resetable, if used in more than once, this may lead to unexpected results.",
                            node.GetChild(2).FirstToken.Image, Line, Column, context.CurrentTemplateName));
                    return (IEnumerator)listObject;

                case EnumType.Array:
                    return ((Array)listObject).GetEnumerator();

                case EnumType.Dictionary:
                    return ((IDictionary)listObject).GetEnumerator();

                default:
                    /*  we have no clue what this is  */
                    runtimeServices.Warn(
                        string.Format(
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:Transformalize,代码行数:101,代码来源:Foreach.cs

示例5: Init

        /// <summary>  
        /// simple init - init the tree and get the elementKey from
        /// the AST
        /// </summary>
        public override void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node)
        {
            base.Init(rs, context, node);

            counterName = runtimeServices.GetString(RuntimeConstants.COUNTER_NAME);
            counterInitialValue = runtimeServices.GetInt(RuntimeConstants.COUNTER_INITIAL_VALUE);

            // this is really the only thing we can do here as everything
            // else is context sensitive
            elementKey = node.GetChild(0).FirstToken.Image.Substring(1);
        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:15,代码来源:Foreach.cs

示例6: Render

		/// <summary>
		/// iterates through the argument list and renders every
		/// argument that is appropriate.  Any non appropriate
		/// arguments are logged, but render() continues.
		/// </summary>
		public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
		{
			// get our arguments and check them
			int argCount = node.ChildrenCount;

			for(int i = 0; i < argCount; i++)
			{
				// we only handle StringLiterals and References right now
				INode n = node.GetChild(i);

				if (n.Type == ParserTreeConstants.STRING_LITERAL || n.Type == ParserTreeConstants.REFERENCE)
				{
					if (!RenderOutput(n, context, writer))
						OutputErrorToStream(writer, "error with arg " + i + " please see log.");
				}
				else
				{
					//UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1043"'
					rsvc.Error("#include() error : invalid argument type : " + n.ToString());
					OutputErrorToStream(writer, "error with arg " + i + " please see log.");
				}
			}

			return true;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:30,代码来源:Include.cs

示例7: Render

		public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
		{
			IEngineContext railsContext = EngineContextLocator.Instance.LocateCurrentContext();
			IViewComponentRegistry registry = railsContext.Services.GetService<IViewComponentFactory>().Registry;
			IViewComponentDescriptorProvider viewDescProvider =
				railsContext.Services.GetService<IViewComponentDescriptorProvider>();
			ICacheProvider cacheProvider = railsContext.Services.CacheProvider;

			INode compNameNode = node.GetChild(0);

			if (compNameNode == null)
			{
				String message = String.Format("You must specify the component name on the #{0} directive", Name);
				throw new ViewComponentException(message);
			}

			string componentName = compNameNode.FirstToken.Image;

			if (componentName == null)
			{
				String message = String.Format("Could not obtain component name from the #{0} directive", Name);
				throw new ViewComponentException(message);
			}

			if (componentName.StartsWith("$"))
			{
				String nodeContent = compNameNode.Literal.Trim('"', '\'');
				SimpleNode inlineNode = runtimeServices.Parse(new StringReader(nodeContent), context.CurrentTemplateName, false);

				inlineNode.Init(context, runtimeServices);
				componentName = (string) Evaluate(inlineNode, context);
			}

			IDictionary componentParams = CreateParameters(context, node);

			Type viewComptype = registry.GetViewComponent(componentName);

			ViewComponentDescriptor descriptor = null;
			CacheKey key = null;

			if (viewComptype != null)
			{
				descriptor = viewDescProvider.Collect(viewComptype);
			}

			bool isOutputtingToCache = false;
			ViewComponentCacheBag bag = null;

			if (descriptor != null && descriptor.IsCacheable)
			{
				key = descriptor.CacheKeyGenerator.Create(componentName, componentParams, railsContext);

				if (key != null)
				{
					ViewComponentCacheBag cachedContent = (ViewComponentCacheBag) cacheProvider.Get(key.ToString());

					if (cachedContent != null)
					{
						// Restore entries

						foreach(KeyValuePair<string, object> pair in cachedContent.ContextEntries)
						{
							context[pair.Key] = pair.Value;
						}

						// Render from cache

						writer.Write(cachedContent.Content);

						return true;
					}

					isOutputtingToCache = true;
					bag = new ViewComponentCacheBag();
				}
			}

			ViewComponent component = viewComponentFactory.Create(componentName);

			if (component == null)
			{
				throw new MonoRailException("ViewComponentFactory returned a null ViewComponent for " + componentName + ". " +
				                            "Please investigate the implementation: " + viewComponentFactory.GetType().FullName);
			}

			try
			{
				ASTDirective directiveNode = (ASTDirective) node;
				IViewRenderer renderer = (IViewRenderer) directiveNode.Directive;

				NVelocityViewContextAdapter contextAdapter = new NVelocityViewContextAdapter(componentName, node, viewEngine, renderer);
				contextAdapter.Context = isOutputtingToCache ? new CacheAwareContext(context, bag) : context;

				INode bodyNode = null;

				if (node.ChildrenCount > 0)
				{
					bodyNode = node.GetChild(node.ChildrenCount - 1);
				}

//.........这里部分代码省略.........
开发者ID:candland,项目名称:Castle.MonoRail,代码行数:101,代码来源:AbstractComponentDirective.cs

示例8: Init

		/// <summary>
		/// Store the literal rendition of a node using
		/// the Node.literal().
		/// </summary>
		public override void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node)
		{
			base.Init(rs, context, node);

			literalText = node.GetChild(0).Literal;
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:10,代码来源:Literal.cs

示例9: AssertArgument

 private bool AssertArgument(INode node)
 {
     bool result = true;
     if (node.GetChild(0) == null)
     {
         runtimeServices.Error("#parse() error :  null argument");
         result = false;
     }
     return result;
 }
开发者ID:rasmus-toftdahl-olesen,项目名称:NVelocity,代码行数:10,代码来源:Parse.cs

示例10: Render

		public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
		{
		    componentName = compNameNode.FirstToken.Image;

		    if (componentName == null)
		    {
		        String message = String.Format("Could not obtain component name from the #{0} directive", Name);
		        throw new ViewComponentException(message);
		    }

		    if (componentName.StartsWith("$"))
		    {
		        String nodeContent = compNameNode.Literal.Trim('"', '\'');
		        SimpleNode inlineNode = rsvc.Parse(new StringReader(nodeContent), context.CurrentTemplateName,
		                                                      false);

		        inlineNode.Init(context, rsvc);
		        componentName = (String) Evaluate(inlineNode, context);
		    }

            ViewComponent component = viewComponentFactory.Create(componentName);

		    
		        ASTDirective directiveNode = (ASTDirective) node;
		        IViewRenderer renderer = (IViewRenderer) directiveNode.Directive;
                NVelocityViewContextAdapter contextAdapter = new NVelocityViewContextAdapter(componentName, node, viewEngine, renderer);
		       contextAdapter.Context = context;



		        INode bodyNode = null;

		        IDictionary componentParams = CreateParameters(context, node);

		        if (node.ChildrenCount > 0)
		        {
		            bodyNode = node.GetChild(node.ChildrenCount - 1);
		        }

		        contextAdapter.BodyNode = bodyNode;
		        contextAdapter.ComponentParams = componentParams;
		        contextAdapter.TextWriter = writer;
                IRailsEngineContext railsContext = MonoRailHttpHandler.CurrentContext;

		        component.Init(railsContext, contextAdapter);

		        ProcessSubSections(component, contextAdapter);

		       

		        const string ViewComponentContextKey = "viewcomponent";
		        var previousComp = context[ViewComponentContextKey];

		        try
		        {
		            context[ViewComponentContextKey] = component;



		            component.Render();

		            if (contextAdapter.ViewToRender != null)
		            {
		                RenderComponentView(context, contextAdapter.ViewToRender, writer, contextAdapter);
		            }
		        }
		        finally
		        {
		            if (previousComp != null)
		            {
		                context[ViewComponentContextKey] = previousComp;
		            }
		            else
		            {
		                context.Remove(ViewComponentContextKey);
		            }
		        }
		    	

			return true;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:81,代码来源:AbstractComponentDirective.cs

示例11: ProcSubtree

    private void ProcSubtree(float tx0, float ty0, float tz0, float tx1, float ty1, float tz1, INode node,
		bool insideSolidNode, int currentDepth, int? wantedDepth,
		Coords nodeCoords)
    {
        if (!_intersectMultiple && results.Count > 0) {
            return;
        }

        if (tx1 < 0.0 || ty1 < 0.0 || tz1 < 0.0) {
            return;
        }

        if (_debug) {
            var entryDistance = Mathf.Max(tx0, ty0, tz0);

            Debug.DrawLine(_ray.origin, _ray.GetPoint(entryDistance), Color.red, 0, false);
        }

        if (wantedDepth == null) {
            if (node == null) {
                return;
            }

            if (node.IsSolid()) {
                ProcessTerminal(node, tx0, ty0, tz0);
                if (results.Count > 0) {
                    return;
                }
            }
        } else {
            if (!insideSolidNode) {
                //didn't manage to get into a solid node
                if (node == null) {
                    return;
                }

                insideSolidNode = node.IsSolid();
            }

            if (insideSolidNode && currentDepth >= wantedDepth) {
                if (currentDepth == wantedDepth) {
                    ProcessTerminal(nodeCoords, tx0, ty0, tz0);
                } else {
                    //oops, went too deep!!!
                    //trace back to wanted depth

                    var newCoords = new OctreeChildCoords[wantedDepth.Value];

                    for (var i = 0; i < newCoords.Length; ++i) {
                        newCoords[i] = nodeCoords.GetCoord(i);
                    }

                    ProcessTerminal(new Coords(newCoords), tx0, ty0,
                        tz0);
                }

                if (results.Count > 0) {
                    return;
                }
            }
        }

        if (_debug) {
            if (node != null) {
                var bounds = node.GetBounds();
                DrawBounds(bounds, Color.white);
            } else {
                //inside solid node and still going strong baby!
                var bounds = _rootNode.GetChildBounds(nodeCoords);
                DrawBounds(bounds, Color.cyan);
            }
        }

        var txm = 0.5f * (tx0 + tx1);
        var tym = 0.5f * (ty0 + ty1);
        var tzm = 0.5f * (tz0 + tz1);

        var currNode = FirstNode(tx0, ty0, tz0, txm, tym, tzm);

        while (currNode < 8) {
            var childIndex = (OctreeNode.ChildIndex) (currNode ^ _dimensionFlipFlags);
            if (!_intersectMultiple && results.Count > 0) {
                return;
            }

            var nextDepth = currentDepth + 1;
            var childCoords = new Coords(nodeCoords,
                OctreeChildCoords.FromIndex(childIndex));

            INode childNode;

            if (insideSolidNode) {
                childNode = null;
            } else {
                childNode = node.GetChild(childIndex);
            }

            switch (currNode) {
                //0= none
                //1 = only x
//.........这里部分代码省略.........
开发者ID:toxicFork,项目名称:vox,代码行数:101,代码来源:RayIntersection.cs

示例12: processAndRegister

		/// <summary>
		/// Used by Parser.java to process VMs within the parsing process
		///
		/// processAndRegister() doesn't actually render the macro to the output
		/// Processes the macro body into the internal representation used by the
		/// VelocimacroProxy objects, and if not currently used, adds it
		/// to the macro Factory
		/// </summary>
		public static void processAndRegister(IRuntimeServices rs, INode node, String sourceTemplate)
		{
			// There must be at least one arg to  #macro,
			// the name of the VM.  Note that 0 following 
			// args is ok for naming blocks of HTML
			int numArgs = node.ChildrenCount;

			// this number is the # of args + 1.  The + 1
			// is for the block tree
			if (numArgs < 2)
			{
				// error - they didn't name the macro or
				// define a block
				rs.Error("#macro error : Velocimacro must have name as 1st argument to #macro()");

				return;
			}

			// get the arguments to the use of the VM
			String[] argArray = getArgArray(node);

			// now, try and eat the code block. Pass the root.
			IList macroArray = getASTAsStringArray(node.GetChild(numArgs - 1));

			// make a big string out of our macro
			StringBuilder temp = new StringBuilder();

			for(int i = 0; i < macroArray.Count; i++)
			{
				temp.Append(macroArray[i]);
			}

			String macroBody = temp.ToString();

			// now, try to add it.  The Factory controls permissions, 
			// so just give it a whack...
			rs.AddVelocimacro(argArray[0], macroBody, argArray, sourceTemplate);

			return;
		}
开发者ID:ralescano,项目名称:castle,代码行数:48,代码来源:Macro.cs

示例13: getArgArray

		/// <summary>  creates an array containing the literal
		/// strings in the macro argument
		/// </summary>
		private static String[] getArgArray(INode node)
		{
			// remember : this includes the block tree
			int numArgs = node.ChildrenCount;

			numArgs--; // avoid the block tree...

			String[] argArray = new String[numArgs];

			int i = 0;

			//  eat the args
			while(i < numArgs)
			{
				argArray[i] = node.GetChild(i).FirstToken.Image;

				// trim off the leading $ for the args after the macro name.
				// saves everyone else from having to do it

				if (i > 0)
				{
					if (argArray[i].StartsWith("$"))
					{
						argArray[i] = argArray[i].Substring(1, (argArray[i].Length) - (1));
					}
				}

				i++;
			}

//			if (debugMode)
//			{
//				Console.Out.WriteLine("Macro.getArgArray() : #args = " + numArgs);
//				Console.Out.Write(argArray[0] + "(");
//
//				for (i = 1; i < numArgs; i++)
//					Console.Out.Write(" " + argArray[i]);
//
//				Console.Out.WriteLine(" )");
//			}

			return argArray;
		}
开发者ID:ralescano,项目名称:castle,代码行数:46,代码来源:Macro.cs

示例14: Render

        /// <summary>
        /// renders the #foreach() block
        /// </summary>
        public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
        {
            // do our introspection to see what our collection is
            IEnumerator enumerator = GetIterator(context, node);
            INode bodyNode = node.GetChild(3);

            INode[][] sections = PrepareSections(bodyNode);
            bool isFancyLoop = (sections != null);

            if (enumerator == null && !isFancyLoop)
            {
                return true;
            }

            int counter = counterInitialValue;

            // save the element key if there is one,
            // and the loop counter
            Object o = context.Get(elementKey);
            Object ctr = context.Get(counterName);

            if (enumerator != null && enumerator.MoveNext())
            {
                do
                {
                    object current = enumerator.Current;

                    context.Put(counterName, counter);
                    //context.Put(hasNextName, enumerator.MoveNext() ? Boolean.TrueString : Boolean.FalseString);
                    context.Put(elementKey, current);

                    try
                    {
                        if (isFancyLoop)
                        {
                            if (counter == counterInitialValue)
                            {
                                ProcessSection(ForeachSectionEnum.BeforeAll, sections, context, writer);
                            }
                            else
                            {
                                ProcessSection(ForeachSectionEnum.Between, sections, context, writer);
                            }

                            ProcessSection(ForeachSectionEnum.Before, sections, context, writer);

                            // since 1st item is zero we invert odd/even
                            if ((counter - counterInitialValue) % 2 == 0)
                            {
                                ProcessSection(ForeachSectionEnum.Odd, sections, context, writer);
                            }
                            else
                            {
                                ProcessSection(ForeachSectionEnum.Even, sections, context, writer);
                            }

                            ProcessSection(ForeachSectionEnum.Each, sections, context, writer);

                            ProcessSection(ForeachSectionEnum.After, sections, context, writer);
                        }
                        else
                        {
                            bodyNode.Render(context, writer);
                        }
                    }
                    catch (BreakException)
                    {
                        break;
                    }
                    counter++;
                } while (enumerator.MoveNext());
            }

            if (isFancyLoop)
            {
                if (counter > counterInitialValue)
                {
                    ProcessSection(ForeachSectionEnum.AfterAll, sections, context, writer);
                }
                else
                {
                    ProcessSection(ForeachSectionEnum.NoData, sections, context, writer);
                }
            }

            // restores the loop counter (if we were nested)
            // if we have one, else just removes
            if (ctr == null)
            {
                context.Remove(counterName);
            }
            else
            {
                context.Put(counterName, ctr);
            }

            // restores element key if exists
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:Transformalize,代码行数:101,代码来源:Foreach.cs

示例15: CreateParameters

		protected virtual IDictionary CreateParameters(IInternalContextAdapter context, INode node)
		{
			int childrenCount = node.ChildrenCount;

			if (childrenCount > 1)
			{
				INode lastNode = node.GetChild(childrenCount - 1);

				if (lastNode.Type == ParserTreeConstants.BLOCK)
				{
					childrenCount--;
				}

				if (childrenCount > 1)
				{
					IDictionary dict = ProcessFirstParam(node, context, childrenCount);

					if (dict != null)
					{
						return dict;
					}
					else if (childrenCount > 2)
					{
						return ProcessRemainingParams(childrenCount, node, context);
					}
				}
			}

			return new Hashtable(0);
		}
开发者ID:candland,项目名称:Castle.MonoRail,代码行数:30,代码来源:AbstractComponentDirective.cs


注:本文中的INode.GetChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。