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


C# BlockStatement.add_Variable方法代码示例

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


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

示例1: ast_CSharp_CreateCompilableClass

        public static string ast_CSharp_CreateCompilableClass(this BlockStatement blockStatement, SnippetParser snippetParser, string codeSnippet,
            CSharp_FastCompiler_CompilerOptions   compilerOptions,
            CSharp_FastCompiler_CompilerArtifacts compilerArtifacts,
            CSharp_FastCompiler_ExecutionOptions  executionOptions)
        {
            if (blockStatement.isNull() || compilerOptions.isNull())
                return null;

            var compilationUnit= compilerArtifacts.CompilationUnit = new CompilationUnit();

            compilationUnit.add_Type(compilerOptions.default_TypeName)
                .add_Method(compilerOptions.default_MethodName, executionOptions.InvocationParameters,
                    compilerOptions.ResolveInvocationParametersType, blockStatement);

            // remove comments from parsed code
            var astCSharp = compilerArtifacts.AstCSharp = new Ast_CSharp(compilerArtifacts.CompilationUnit, snippetParser.Specials);

            // add references included in the original source code file
            compilerArtifacts.AstCSharp.mapCodeO2References(compilerOptions);

            astCSharp.mapAstDetails();

            astCSharp.ExtraSpecials.Clear();
            var method     = compilationUnit.method(compilerOptions.default_MethodName);
            var returntype = method.returnType();
            var type       = compilationUnit.type(compilerOptions.default_TypeName);

            type.Children.Clear();
            var tempBlockStatement = new BlockStatement();
            tempBlockStatement.add_Variable("a", 0);
            method.Body = tempBlockStatement;
            var newMethod = type.add_Method(compilerOptions.default_MethodName, executionOptions.InvocationParameters,
                compilerOptions.ResolveInvocationParametersType, tempBlockStatement);
            newMethod.TypeReference = returntype;

            if(blockStatement.returnStatements().size() >1)
                astCSharp.methodDeclarations().first().remove_LastReturnStatement();

            astCSharp.mapAstDetails();

            var codeToReplace = "Int32 a = 0;";
            var csharpCode = astCSharp.AstDetails.CSharpCode
                .replace("\t\t{0}".format(codeToReplace), codeToReplace)    // remove tabs
                .replace("Int32 a = 0;", codeSnippet);                      // put the actual code (this should be done via AST, but it was affectting code complete)
            return csharpCode;
        }
开发者ID:njmube,项目名称:FluentSharp,代码行数:46,代码来源:Ast_CSharp_ExtensionMethods_Code_Generation.cs

示例2: tryToCreateCSharpCodeWith_Class_Method_WithMethodText

        //this code needs to be completely rewritten
        public string tryToCreateCSharpCodeWith_Class_Method_WithMethodText(string code)
        {
            if (code.empty())
                return null;
            code = code.line();	// make sure there is an empty line at the end

            try
            {
                //handle special incudes in source code
                var lines = code.fix_CRLF().lines();
                foreach (var originalLine in lines)
                {
                    string line = originalLine;
                    originalLine.starts("//O2Include:", (includeText) =>
                        {
                            var file = includeText;
                            var baseFile = SourceCodeFile ?? PublicDI.CurrentScript;
                            var parentFolder = baseFile.parentFolder();
                            if (parentFolder.notValid())
                                "[CSharpFastCompiled] in O2Include mapping, could not get parent folder of current script".error();
                            var resolvedFile = CompileEngine.findFileOnLocalScriptFolder(file,parentFolder);
                            if (resolvedFile.fileExists())
                            {
                                var fileContents = resolvedFile.contents();
                                code = code.Replace(line, line.line().add(fileContents).line());
                            }
                            else
                                "[CSharpFastCompiled] in O2Include mapping, could not a mapping for: {0}".error(includeText);
                        });
                }

                var snippetParser = new SnippetParser(SupportedLanguage.CSharp);

                var parsedCode = snippetParser.Parse(code);
                AstErrors = snippetParser.errors();
                CompilationUnit = new CompilationUnit();

                if (parsedCode is BlockStatement || parsedCode is CompilationUnit)
                {
                    Ast_CSharp astCSharp;
                    if (parsedCode is BlockStatement)
                    {
                        // map parsedCode into a new type and method
                        var blockStatement = (BlockStatement)parsedCode;
                        CompilationUnit.add_Type(default_TypeName)
                            .add_Method(default_MethodName, InvocationParameters, this.ResolveInvocationParametersType, blockStatement);

                        // remove comments from parsed code
                        astCSharp = new Ast_CSharp(CompilationUnit, snippetParser.Specials);

                        // add references included in the original source code file
                        mapCodeO2References(astCSharp);

                        astCSharp.mapAstDetails();

                        astCSharp.ExtraSpecials.Clear();
                        var method = CompilationUnit.method(default_MethodName);
                        var returntype = method.returnType();
                        var type = CompilationUnit.type(default_TypeName);

                        type.Children.Clear();
                        var tempBlockStatement = new BlockStatement();
                        tempBlockStatement.add_Variable("a", 0);
                        method.Body = tempBlockStatement;
                        var newMethod = type.add_Method(default_MethodName, InvocationParameters, this.ResolveInvocationParametersType, tempBlockStatement);
                        newMethod.TypeReference = returntype;
                        astCSharp.mapAstDetails();
                        var csharpCode = astCSharp.AstDetails.CSharpCode
                                                  .replace("Int32 a = 0;", code);

                        AstDetails = new Ast_CSharp(csharpCode).AstDetails;
                        CreatedFromSnipptet = true;
                        DebugMode.ifDebug("Ast parsing was OK");
                        SourceCode = csharpCode;
                        onAstOK.invoke();

                        return csharpCode;
                    }

                    CompilationUnit = (CompilationUnit)parsedCode;
                    if (CompilationUnit.Children.Count == 0)
                        return null;

                    astCSharp = new Ast_CSharp(CompilationUnit, snippetParser.Specials);
                    // add the comments from the original code

                    mapCodeO2References(astCSharp);
                    CreatedFromSnipptet = false;

                    // create sourceCode using Ast_CSharp & AstDetails
                    if(CompilationUnit.Children.Count > 0)
                    {
                        // reset the astCSharp.AstDetails object
                        astCSharp.mapAstDetails();
                        // add the comments from the original code
                        astCSharp.ExtraSpecials.AddRange(snippetParser.Specials);

                        SourceCode = astCSharp.AstDetails.CSharpCode;

//.........这里部分代码省略.........
开发者ID:sempf,项目名称:FluentSharp,代码行数:101,代码来源:Charp_FastCompiler.cs


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