示例#1
0
        public GenerateCSharpCodeResult GenerateCode(string code)
        {
            string file = _sourceFile;
            using (StreamWriter sw = zFile.CreateText(file))
            {
                CSharpCodeWriter codeWriter = new CSharpCodeWriter(sw);

                // using
                codeWriter.WriteUsings(_usings.Keys);

                // open namespace
                codeWriter.OpenNameSpace(_nameSpace);

                // open class
                // public static partial class ...
                codeWriter.OpenClass(_runTypeName, ClassOptions.Public | ClassOptions.Static | ClassOptions.Partial);

                // open function
                // public static void Run()
                if (_runMethodName == null)
                    throw new PBException("run method name is null, can't open method");
                codeWriter.WriteLine("public static void {0}()", _runMethodName);
                codeWriter.WriteLine("{");
                codeWriter.WriteLine(code);
                codeWriter.WriteLine("}");

                // close class
                codeWriter.CloseClass();

                // close namespace
                codeWriter.CloseNameSpace();
            }
            return new GenerateCSharpCodeResult { SourceFile = _sourceFile, NameSpace = _nameSpace, TypeName = _runTypeName, RunMethodName = _runMethodName };
        }
示例#2
0
        public void GenerateCSharpCode(string code)
        {
            string file = zpath.PathSetExtension(_assemblyFilename, ".cs");

            using (StreamWriter sw = zFile.CreateText(file))
            {
                CSharpCodeWriter generateCode = new CSharpCodeWriter(sw);

                // using
                generateCode.WriteUsings(_usings.Keys);

                // open namespace
                generateCode.OpenNameSpace(_nameSpace);

                // open class
                // public static partial class ...
                generateCode.OpenClass(_className, ClassOptions.Public | ClassOptions.Static | ClassOptions.Partial);

                // open function
                // public static void Run()
                generateCode.WriteLine("public static void {0}()", _runMethodName);
                generateCode.WriteLine("{");
                generateCode.WriteLine(code);
                generateCode.WriteLine("}");

                // close class
                generateCode.CloseClass();

                // close namespace
                generateCode.CloseNameSpace();
            }
            _compiler.AddSource(new CompilerFile(file));
        }
示例#3
0
        public GenerateCSharpCodeResult GenerateCode(string code)
        {
            string file = _sourceFile;

            using (StreamWriter sw = zFile.CreateText(file))
            {
                CSharpCodeWriter codeWriter = new CSharpCodeWriter(sw);

                // using
                codeWriter.WriteUsings(_usings.Keys);

                // open namespace
                codeWriter.OpenNameSpace(_nameSpace);

                // open class
                // public static partial class ...
                codeWriter.OpenClass(_runTypeName, ClassOptions.Public | ClassOptions.Static | ClassOptions.Partial);

                // open function
                // public static void Run()
                if (_runMethodName == null)
                {
                    throw new PBException("run method name is null, can't open method");
                }
                //codeWriter.WriteLine("public static void {0}()", _runMethodName);
                // Warning CS1998 source "RunCode_00006.cs" line 17 col 49 "This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread."
                codeWriter.WriteLine("#pragma warning disable 1998");
                codeWriter.WriteLine($"public static async System.Threading.Tasks.Task {_runMethodName}()");
                codeWriter.WriteLine("#pragma warning restore 1998");
                codeWriter.WriteLine("{");
                codeWriter.WriteLine(code);
                codeWriter.WriteLine("}");

                // close class
                codeWriter.CloseClass();

                // close namespace
                codeWriter.CloseNameSpace();
            }
            return(new GenerateCSharpCodeResult {
                SourceFile = _sourceFile, NameSpace = _nameSpace, TypeName = _runTypeName, RunMethodName = _runMethodName
            });
        }
示例#4
0
        public void GenerateCSharpCode(string code)
        {
            string file = zpath.PathSetExtension(_assemblyFilename, ".cs");
            using (StreamWriter sw = zFile.CreateText(file))
            {
                CSharpCodeWriter generateCode = new CSharpCodeWriter(sw);

                // using
                generateCode.WriteUsings(_usings.Keys);

                // open namespace
                generateCode.OpenNameSpace(_nameSpace);

                // open class
                // public static partial class ...
                generateCode.OpenClass(_className, ClassOptions.Public | ClassOptions.Static | ClassOptions.Partial);

                // open function
                // public static void Run()
                generateCode.WriteLine("public static void {0}()", _runMethodName);
                generateCode.WriteLine("{");
                generateCode.WriteLine(code);
                generateCode.WriteLine("}");

                // close class
                generateCode.CloseClass();

                // close namespace
                generateCode.CloseNameSpace();
            }
            _compiler.AddSource(new CompilerFile(file));
        }