本文整理汇总了C#中DotLiquid.Context.ShapeIsWithinAllowedRecursionDepth方法的典型用法代码示例。如果您正苦于以下问题:C# Context.ShapeIsWithinAllowedRecursionDepth方法的具体用法?C# Context.ShapeIsWithinAllowedRecursionDepth怎么用?C# Context.ShapeIsWithinAllowedRecursionDepth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotLiquid.Context
的用法示例。
在下文中一共展示了Context.ShapeIsWithinAllowedRecursionDepth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Display
public static string Display(Context context, dynamic input)
{
if (input == null || !(input is StaticShape)) return string.Empty;
StaticShape shape = input;
var wc = context.GetWorkContext();
// Checking if the shape is displayed multiple times. If yes it can be legitimate (although rare) but
// can also indicate unwanted recursion, so capping it.
if (shape.Shape.DisplayedCount == null) shape.Shape.DisplayedCount = 0;
if (shape.Shape.DisplayedCount >= Constants.MaxAllowedShapeDisplayCount)
{
wc.LogSecurityNotificationWithContext(typeof(DisplayFilter), "Too many displays of the same shape prevented.");
return string.Empty;
}
shape.Shape.DisplayedCount++;
if (!context.ShapeIsWithinAllowedRecursionDepth(shape.Metadata.Type))
{
wc.LogSecurityNotificationWithContext(typeof(DisplayFilter), "Too many recursive shape displays prevented.");
return string.Empty;
}
context.AddCurrentShapeAsParentToShape((IShape)shape.Shape);
return wc.Resolve<IShapeDisplay>().Display(shape.Shape);
}
示例2: Render
public override void Render(Context context, TextWriter result)
{
if (string.IsNullOrEmpty(_shapeType)) return;
var wc = context.GetWorkContext();
if (!context.ShapeIsWithinAllowedRecursionDepth(_shapeType))
{
wc.LogSecurityNotificationWithContext(typeof(DisplayTag), "Too many recursive shape displays prevented.");
return;
}
var argumentsDictionary = _arguments.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.EvaluateAsParameter(context));
var shape = wc.Resolve<IShapeFactory>().Create(_shapeType, Arguments.From(argumentsDictionary));
context.AddCurrentShapeAsParentToShape(shape);
result.Write(wc.Resolve<IShapeDisplay>().Display(shape));
}