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


C# DataContext.PopCodeBlock方法代码示例

本文整理汇总了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();
        }
开发者ID:smack0007,项目名称:Snowflake,代码行数:101,代码来源:CodeGenerator.cs


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