本文整理汇总了C#中DataContext.PopCodeBlock方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.PopCodeBlock方法的具体用法?C# DataContext.PopCodeBlock怎么用?C# DataContext.PopCodeBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContext
的用法示例。
在下文中一共展示了DataContext.PopCodeBlock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateFunction
//.........这里部分代码省略.........
if (capturedVariables.Length > 0)
{
Append(data, "new dynamic[] {{ ");
for (int i = 0; i < capturedVariables.Length; i++)
{
if (i != 0)
Append(data, ", ");
Append(data, "context[\"{0}\"]", capturedVariables[i].VariableName);
}
Append(data, " }}");
}
else
{
Append(data, "null");
}
Append(data, ")");
data.PushCodeBlock(functionName);
data.CodeBlock.Padding = 2;
string returnType = "dynamic";
if (node.IsGenerator)
returnType = "IEnumerable<dynamic>";
Append(data, "private static {0} {1}(ScriptExecutionContext context, dynamic[] captures", returnType, functionName);
if (node.Args.Count > 0)
{
Append(data, ", ");
Append(data, string.Join(", ", node.Args.Select(x => "dynamic " + data.VariableMap.GetVariableName(x.VariableName))));
}
EndLine(data, ")");
WriteLine(data, "{{");
data.CodeBlock.Padding++;
if (!node.IsGenerator)
WriteLine(data, "context.PushStackFrame(\"{0}\");", !node.IsAnonymous ? node.FunctionName : "<anonymous>");
foreach (var arg in node.Args)
WriteLine(data, "context.DeclareVariable(\"{0}\", {1});", arg.VariableName, data.VariableMap.GetVariableName(arg.VariableName));
for (int i = 0; i < capturedVariables.Length; i++)
WriteLine(data, "context.DeclareVariable(\"{0}\", captures[{1}]);", capturedVariables[i].VariableName, i);
if (!node.IsGenerator)
{
WriteLine(data, "bool isError = false;");
WriteLine(data, "try {{");
data.CodeBlock.Padding++;
}
GenerateStatementBlock(node.BodyStatementBlock, data, pushStackFrame: false);
if (!(node.BodyStatementBlock.Last() is ReturnNode) && !node.IsGenerator)
{
WriteLine(data, "return null;");
}
if (!node.IsGenerator)
{
data.CodeBlock.Padding--;
WriteLine(data, "}} catch(Exception) {{");
data.CodeBlock.Padding++;
WriteLine(data, "isError = true;");
WriteLine(data, "throw;");
data.CodeBlock.Padding--;
WriteLine(data, "}} finally {{");
data.CodeBlock.Padding++;
WriteLine(data, "if (!isError) {{");
data.CodeBlock.Padding++;
WriteLine(data, "context.PopStackFrame();");
data.CodeBlock.Padding--;
WriteLine(data, "}}");
data.CodeBlock.Padding--;
WriteLine(data, "}}");
}
data.CodeBlock.Padding--;
WriteLine(data, "}}");
data.PopCodeBlock();
data.VariableMap.PopFrame();
}