本文整理汇总了C#中SymbolTable.DefineLocalVariable方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolTable.DefineLocalVariable方法的具体用法?C# SymbolTable.DefineLocalVariable怎么用?C# SymbolTable.DefineLocalVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.DefineLocalVariable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: It_Should_Save_A_Variable
public void It_Should_Save_A_Variable()
{
// Arrange
var symbolTable = new SymbolTable();
var str = new StringValue("FOO");
// Act
symbolTable.DefineLocalVariable("foo", str);
// Assert
Assert.That(symbolTable.ReferenceLocalVariable("foo").SuccessValue<StringValue>(), Is.EqualTo(str));
}
示例2: It_Should_Find_An_Array
// TODO: clean this up
public void It_Should_Find_An_Array()
{
// Arrange
const string varname = "objlist";
var arrayValue = CreateArrayValue();
var symbolTable = new SymbolTable();
symbolTable.DefineLocalVariable(varname, arrayValue);
// Act
var arr = symbolTable.ReferenceLocalVariable(varname).SuccessValue<ArrayValue>();
// Assert
Assert.That(arr, Is.TypeOf<ArrayValue>());
}
示例3: Render
public StringValue Render(
RenderingVisitor renderingVisitor,
MacroBlockTag macroBlocktag,
ITemplateContext templateContext,
IList<Option<IExpressionConstant>> args)
{
var macroScope = new SymbolTable();
var i = 0;
foreach (var varName in macroBlocktag.Args.Take(args.Count))
{
macroScope.DefineLocalVariable(varName, args[i].HasValue? args[i].Value : null);
i++;
}
templateContext.SymbolTableStack.Push(macroScope);
//String result = "";
//var subRenderer = new RenderingVisitor(evaluator, templateContext, str => result += str);
//evaluator.StartVisiting(subRenderer, macroBlocktag.LiquidBlock);
String hiddenText = "";
renderingVisitor.PushTextAccumulator(str => hiddenText += str);
renderingVisitor.StartWalking(macroBlocktag.LiquidBlock);
renderingVisitor.PopTextAccumulator();
templateContext.SymbolTableStack.Pop();
// foreach (var error in subRenderer.Errors)
// {
// errorAccumulator.Add(error);
// }
return new StringValue(hiddenText);
}
示例4: Render
public void Render(IncludeTag includeTag, ITemplateContext templateContext)
{
var virtualFilenameVar = LiquidExpressionEvaluator.Eval(includeTag.VirtualFileExpression, templateContext);
if (virtualFilenameVar.IsError)
{
_renderingVisitor.Errors.Add(virtualFilenameVar.ErrorResult);
return;
}
String virtualFileName = ValueCaster.RenderAsString(virtualFilenameVar.SuccessResult.Value);
if (templateContext.FileSystem == null)
{
_renderingVisitor.Errors.Add(new LiquidError{Message = " ERROR: FileSystem is not defined"});
return;
}
String snippet = templateContext.FileSystem.Include(templateContext, virtualFileName);
templateContext.SymbolTableStack.DefineLocalRegistry(LOCALREGISTRY_FILE_KEY, virtualFileName);
LiquidAST snippetAst;
try
{
//snippetAst = GenerateSnippetAst(snippet);
snippetAst = templateContext.ASTGenerator(snippet);
}
catch (LiquidParserException ex)
{
foreach (var error in ex.LiquidErrors)
{
if (String.IsNullOrEmpty(error.TokenSource))
{
error.TokenSource = virtualFileName;
}
}
throw;
}
if (includeTag.ForExpression != null)
{
var forExpressionOption = LiquidExpressionEvaluator.Eval(includeTag.ForExpression, templateContext);
if (forExpressionOption.IsError)
{
_renderingVisitor.Errors.Add(forExpressionOption.ErrorResult);
return;
}
if (forExpressionOption.SuccessResult.Value is DictionaryValue) // it seems to render as a single element if it's a dictionary.
{
var localBlockScope = new SymbolTable();
DefineLocalVariables(templateContext, localBlockScope, includeTag.Definitions);
var exprValue = LiquidExpressionEvaluator.Eval(includeTag.ForExpression, templateContext);
localBlockScope.DefineLocalVariable(virtualFileName, exprValue.SuccessResult.Value);
RenderWithLocalScope(templateContext, localBlockScope, snippetAst.RootNode);
}
else
{
//ArrayValue array = ValueCaster.Cast<IExpressionConstant, ArrayValue>(forExpressionOption.SuccessResult.Value);
var arrayResult = ValueCaster.Cast<IExpressionConstant, ArrayValue>(forExpressionOption.SuccessResult.Value);
if (arrayResult.IsError)
{
_renderingVisitor.Errors.Add(arrayResult.ErrorResult);
return;
}
// if (array.HasError)
// {
// _renderingVisitor.Errors.Add(new LiquidError {Message = array.ErrorMessage});
// return;
// }
foreach (Option<IExpressionConstant> val in arrayResult.SuccessValue<ArrayValue>())
{
var localBlockScope = new SymbolTable();
DefineLocalVariables(templateContext, localBlockScope, includeTag.Definitions);
if (val.HasValue)
{
localBlockScope.DefineLocalVariable(virtualFileName, val.Value);
}
else
{
localBlockScope.DefineLocalVariable(virtualFileName, null);
}
RenderWithLocalScope(templateContext, localBlockScope, snippetAst.RootNode);
}
}
}
else
{
var localBlockScope = new SymbolTable();
DefineLocalVariables(templateContext, localBlockScope, includeTag.Definitions);
if (includeTag.WithExpression != null)
{
var withExpression = LiquidExpressionEvaluator.Eval(includeTag.WithExpression, templateContext);
localBlockScope.DefineLocalVariable(virtualFileName, withExpression.SuccessResult.Value);
}
RenderWithLocalScope(templateContext, localBlockScope, snippetAst.RootNode);
}
}
示例5: DefineLocalVariables
private static void DefineLocalVariables(
ITemplateContext templateContext,
SymbolTable localBlockScope,
IDictionary<string, TreeNode<LiquidExpression>> definitions)
{
foreach (var def in definitions)
{
var liquidExpressionREsult = LiquidExpressionEvaluator.Eval(def.Value, templateContext);
if (liquidExpressionREsult.IsError)
{
// TODO: check if this should ignore this or not.
}
localBlockScope.DefineLocalVariable(def.Key,
liquidExpressionREsult.SuccessResult.HasValue
? liquidExpressionREsult.SuccessResult.Value
: null);
}
}