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


C# Context.Stack方法代码示例

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


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

示例1: Render

 public override void Render(Context context, TextWriter result)
 {
     context.Stack(() =>
     {
         context.Registers["current_page"] = _page;
     });
 }
开发者ID:neilkinnish,项目名称:dotliquid,代码行数:7,代码来源:CurrentPage.cs

示例2: Render

        public override void Render(Context context, StreamWriter result)
        {
            IFileSystem fileSystem = context.Registers["file_system"] as IFileSystem ?? Template.FileSystem;
            string source = fileSystem.ReadTemplateFile(context, _templateName);
            Template partial = Template.Parse(source);

            string shortenedTemplateName = _templateName.Substring(1, _templateName.Length - 2);
            object variable = context[_variableName ?? shortenedTemplateName];

            context.Stack(() =>
            {
                foreach (var keyValue in _attributes)
                    context[keyValue.Key] = context[keyValue.Value];

                if (variable is IEnumerable)
                {
                    ((IEnumerable)variable).Cast<object>().ToList().ForEach(v =>
                    {
                        context[shortenedTemplateName] = v;
                        partial.Render(result, RenderParameters.FromContext(context));
                    });
                    return;
                }

                context[shortenedTemplateName] = variable;
                partial.Render(result, RenderParameters.FromContext(context));
            });
        }
开发者ID:devSolo,项目名称:dotliquid,代码行数:28,代码来源:Include.cs

示例3: Render

 public override void Render(Context context, StringBuilder result)
 {
     context.Stack(() =>
     {
         context["block"] = new BlockDrop(this);
         RenderAll(NodeList, context, result);
     });
 }
开发者ID:ChadBurggraf,项目名称:dotliquid,代码行数:8,代码来源:Block.cs

示例4: Render

 public override void Render(Context context, TextWriter result)
 {
     BlockRenderState blockState = BlockRenderState.Find(context);
     context.Stack(() =>
     {
         context["block"] = new BlockDrop(this, result);
         RenderAll(GetNodeList(blockState), context, result);
     });
 }
开发者ID:ostapkoenig,项目名称:dotliquid,代码行数:9,代码来源:Block.cs

示例5: Render

        public override void Render(Context context, StreamWriter result)
        {
            _result = result;

            context.Stack(() =>
            {
                context["block"] = new BlockDrop(this);
                RenderAll(NodeList, context, result);
            });
        }
开发者ID:devSolo,项目名称:dotliquid,代码行数:10,代码来源:Block.cs

示例6: Render

 public override void Render(Context context, TextWriter result)
 {
     context.Stack(() =>
     {
         foreach (Condition block in Blocks)
         {
             if (block.Evaluate(context))
             {
                 RenderAll(block.Attachment, context, result);
                 return;
             }
         }
     });
 }
开发者ID:Elph,项目名称:dotliquid,代码行数:14,代码来源:If.cs

示例7: Render

        public override void Render(Context context, TextWriter result)
        {
            context.Registers["cycle"] = context.Registers["cycle"] ?? new Hash(0);

            context.Stack(() =>
            {
                string key = context[_name].ToString();
                int iteration = (int) (((Hash) context.Registers["cycle"])[key] ?? 0);
                result.Write(context[_variables[iteration]].ToString());
                ++iteration;
                if (iteration >= _variables.Length)
                    iteration = 0;
                ((Hash) context.Registers["cycle"])[key] = iteration;
            });
        }
开发者ID:tt,项目名称:dotliquid,代码行数:15,代码来源:Cycle.cs

示例8: Render

        public override void Render(Context context, StringBuilder result)
        {
            context.Stack(() =>
            {
                StringBuilder temp = new StringBuilder();
                RenderAll(NodeList, context, temp);
                string tempString = temp.ToString();

                if (tempString != (context.Registers["ifchanged"] as string))
                {
                    context.Registers["ifchanged"] = tempString;
                    result.Append(tempString);
                }
            });
        }
开发者ID:ChadBurggraf,项目名称:dotliquid,代码行数:15,代码来源:IfChanged.cs

示例9: Render

		public override void Render(Context context, TextWriter result)
		{
			context.Stack(() =>
			{
				string tempString;
				using (TextWriter temp = new StringWriter())
				{
					RenderAll(NodeList, context, temp);
					tempString = temp.ToString();
				}

				if (tempString != (context.Registers["ifchanged"] as string))
				{
					context.Registers["ifchanged"] = tempString;
					result.Write(tempString);
				}
			});
		}
开发者ID:nZeus,项目名称:dotliquid,代码行数:18,代码来源:IfChanged.cs

示例10: Render

        public override void Render(Context context, StringBuilder result)
        {
            context.Stack(() =>
            {
                // First condition is interpreted backwards (if not)
                Condition block = Blocks.First();
                if (!block.Evaluate(context))
                {
                    RenderAll(block.Attachment, context, result);
                    return;
                }

                // After the first condition unless works just like if
                foreach (Condition forEachBlock in Blocks.Skip(1))
                    if (forEachBlock.Evaluate(context))
                    {
                        RenderAll(forEachBlock.Attachment, context, result);
                        return;
                    }
            });
        }
开发者ID:ChadBurggraf,项目名称:dotliquid,代码行数:21,代码来源:Unless.cs

示例11: Render

 public override void Render(Context context, TextWriter result)
 {
     context.Stack(() =>
     {
         bool executeElseBlock = true;
         _blocks.ForEach(block =>
         {
             if (block.IsElse)
             {
                 if (executeElseBlock)
                 {
                     RenderAll(block.Attachment, context, result);
                     return;
                 }
             }
             else if (block.Evaluate(context))
             {
                 executeElseBlock = false;
                 RenderAll(block.Attachment, context, result);
             }
         });
     });
 }
开发者ID:Elph,项目名称:dotliquid,代码行数:23,代码来源:Case.cs

示例12: Render

		public override void Render(Context context, TextWriter result)
		{
			context.Registers["for"] = context.Registers["for"] ?? new Hash(0);

			object collection = context[_collectionName];

			if (!(collection is IEnumerable))
				return;

			int from = (_attributes.ContainsKey("offset"))
				? (_attributes["offset"] == "continue")
					? Convert.ToInt32(context.Registers.Get<Hash>("for")[_name])
					: Convert.ToInt32(context[_attributes["offset"]])
				: 0;

			int? limit = _attributes.ContainsKey("limit") ? context[_attributes["limit"]] as int? : null;
			int? to = (limit != null) ? (int?) (limit.Value + from) : null;

			List<object> segment = SliceCollectionUsingEach((IEnumerable) collection, from, to);

			if (!segment.Any())
				return;

			if (_reversed)
				segment.Reverse();

			int length = segment.Count;

			// Store our progress through the collection for the continue flag
			context.Registers.Get<Hash>("for")[_name] = from + length;

			context.Stack(() => segment.EachWithIndex((item, index) =>
			{
				context[_variableName] = item;
				context["forloop"] = Hash.FromAnonymousObject(new
				{
					name = _name,
					length = length,
					index = index + 1,
					index0 = index,
					rindex = length - index,
					rindex0 = length - index - 1,
					first = (index == 0),
					last = (index == length - 1)
				});
				RenderAll(NodeList, context, result);
			}));
		}
开发者ID:nZeus,项目名称:dotliquid,代码行数:48,代码来源:For.cs

示例13: Render

        public override void Render(Context context, TextWriter result)
        {
            object coll = context[_collectionName];

            if (!(coll is IEnumerable))
                return;
            IEnumerable<object> collection = ((IEnumerable) coll).Cast<object>();

            if (_attributes.ContainsKey("limit") || _attributes.ContainsKey("offset"))
            {
                int limit = _attributes.ContainsKey("limit") ? Convert.ToInt32("limit") : -1;
                int offset = _attributes.ContainsKey("offset") ? Convert.ToInt32("offset") : 0;
                collection = collection.Skip(offset).Take(limit);
            }

            collection = collection.ToList();
            int length = collection.Count();

            int cols = Convert.ToInt32(context[_attributes["cols"]]);

            int row = 1;
            int col = 0;

            result.WriteLine("<tr class=\"row1\">");
            context.Stack(() => collection.EachWithIndex((item, index) =>
            {
                context[_variableName] = item;
                context["tablerowloop"] = Hash.FromAnonymousObject(new
                {
                    length = length,
                    index = index + 1,
                    index0 = index,
                    col = col + 1,
                    col0 = col,
                    rindex = length - index,
                    rindex0 = length - index - 1,
                    first = (index == 0),
                    last = (index == length - 1),
                    col_first = (col == 0),
                    col_last = (col == cols - 1)
                });

                ++col;

                using (TextWriter temp = new StringWriter())
                {
                    RenderAll(NodeList, context, temp);
                    result.Write("<td class=\"col{0}\">{1}</td>", col, temp.ToString());
                }

                if (col == cols && index != length - 1)
                {
                    col = 0;
                    ++row;
                    result.WriteLine("</tr>");
                    result.Write("<tr class=\"row{0}\">", row);
                }
            }));
            result.WriteLine("</tr>");
        }
开发者ID:RevCBH,项目名称:dotliquid,代码行数:60,代码来源:TableRow.cs

示例14: Render

		public override void Render(Context context, TextWriter result)
		{
            // Get the template or template content and then either copy it (since it will be modified) or parse it
			IFileSystem fileSystem = context.Registers["file_system"] as IFileSystem ?? Template.FileSystem;
            object file = fileSystem.ReadTemplateFile(context, _templateName);
		    Template template = file as Template;
            template = template ?? Template.Parse(file == null ? null : file.ToString());

		    List<Block> parentBlocks = FindBlocks(template.Root, null);
            List<Block> orphanedBlocks = ((List<Block>)context.Scopes[0]["extends"]) ?? new List<Block>();
		    BlockRenderState blockState = BlockRenderState.Find(context) ?? new BlockRenderState();

            context.Stack(() =>
            {
                context["blockstate"] = blockState;         // Set or copy the block state down to this scope
                context["extends"] = new List<Block>();     // Holds Blocks that were not found in the parent
                foreach (Block block in NodeList.OfType<Block>().Concat(orphanedBlocks))
                {
                    Block pb = parentBlocks.Find(b => b.BlockName == block.BlockName);
                    
                    if (pb != null)
                    {
                        Block parent;
                        if (blockState.Parents.TryGetValue(block, out parent))
                            blockState.Parents[pb] = parent;
                        pb.AddParent(blockState.Parents, pb.GetNodeList(blockState));
                        blockState.NodeLists[pb] = block.GetNodeList(blockState);
                    }
                    else if(IsExtending(template))
                    {
                        ((List<Block>)context.Scopes[0]["extends"]).Add(block);
                    }
                }
			    template.Render(result, RenderParameters.FromContext(context));
            });
		}
开发者ID:nZeus,项目名称:dotliquid,代码行数:36,代码来源:Extends.cs

示例15: Render

        public override void Render(Context context, TextWriter result)
        {
            context.Registers["for"] = context.Registers["for"] ?? new Hash(0);

            object collection = context[_collectionName];

            if (!(collection is IEnumerable))
                return;

            int from = (_attributes.ContainsKey("offset"))
                ? (_attributes["offset"] == "continue")
                    ? Convert.ToInt32(context.Registers.Get<Hash>("for")[_name])
                    : Convert.ToInt32(context[_attributes["offset"]])
                : 0;

            int? limit = _attributes.ContainsKey("limit") ? context[_attributes["limit"]] as int? : null;
            int? to = (limit != null) ? (int?) (limit.Value + from) : null;

            List<object> segment = SliceCollectionUsingEach((IEnumerable) collection, from, to);

            if (!segment.Any())
                return;

            if (_reversed)
                segment.Reverse();

            int length = segment.Count;

            // Store our progress through the collection for the continue flag
            context.Registers.Get<Hash>("for")[_name] = from + length;

            context.Stack(() =>
            {
                for (var index = 0; index < segment.Count; index++)
                {
                    var item = segment[index];
                    if (item is KeyValuePair<string,object>)
                    {
                        var itemKey = ((KeyValuePair<string, object>) item).Key;
                        var itemValue = ((KeyValuePair<string, object>) item).Value;
                        buildContext(context, _variableName, itemKey, itemValue);

                    } else 
                        context[_variableName] = item;
                    
                    context["forloop"] = Hash.FromAnonymousObject(new
                    {
                        name = _name,
                        length = length,
                        index = index + 1,
                        index0 = index,
                        rindex = length - index,
                        rindex0 = length - index - 1,
                        first = (index == 0),
                        last = (index == length - 1)
                    });
                    try
                    {
                        RenderAll(NodeList, context, result);
                    }
                    catch (BreakInterrupt)
                    {
                        break;
                    }
                    catch (ContinueInterrupt)
                    {
                    }
                }
            });
        }
开发者ID:Elph,项目名称:dotliquid,代码行数:70,代码来源:For.cs


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