コード例 #1
0
        //-----------------------------------------------------------------------------
        // Internal Methods
        //-----------------------------------------------------------------------------
        // Compile the final code for a script only to find any errors and/or warnings.
        private static ScriptCompileResult CompileScript(string code)
        {
            // Setup the compile options.
            CompilerParameters options	= new CompilerParameters();
            options.GenerateExecutable	= false; // We want a Dll (Class Library)
            options.GenerateInMemory	= true;

            // Add the assembly references.
            Assembly zeldaApiAssembly = Assembly.GetAssembly(typeof(ZeldaAPI.CustomScriptBase));
            options.ReferencedAssemblies.Add(zeldaApiAssembly.Location);

            // Create a C# code provider and compile the code.
            Microsoft.CSharp.CSharpCodeProvider csProvider = new Microsoft.CSharp.CSharpCodeProvider();
            CompilerResults csResult = csProvider.CompileAssemblyFromSource(options, code);

            // Copy warnings and errors into the ScriptComileResult.
            ScriptCompileResult result	= new ScriptCompileResult();
            foreach (CompilerError csError in csResult.Errors) {
                ScriptCompileError error = new ScriptCompileError(csError.Line,
                    csError.Column, csError.ErrorNumber, csError.ErrorText, csError.IsWarning);
                if (error.IsWarning)
                    result.Warnings.Add(error);
                else
                    result.Errors.Add(error);
            }

            return result;
        }
コード例 #2
0
ファイル: Script.cs プロジェクト: radtek/ZeldaOracle
 public ScriptCompileError(ScriptCompileError copy)
 {
     Line        = copy.Line;
     Column      = copy.Column;
     ErrorNumber = copy.ErrorNumber;
     ErrorText   = copy.ErrorText;
     IsWarning   = copy.IsWarning;
 }
コード例 #3
0
        // Compile all the scripts into one assembly.
        public ScriptCompileResult Compile(string code)
        {
            ScriptCompileResult result = new ScriptCompileResult();
            string pathToAssembly      = "";
            bool   hasErrors           = false;

            // Setup the compile options.
            CompilerParameters options = new CompilerParameters();

            options.GenerateExecutable = false;                         // We want a Dll (Class Library)
            options.GenerateInMemory   = false;                         // Save the assembly to a file.
            options.OutputAssembly     = "ZWD2CompiledScript.dll";

            // Add the assembly references.
            options.ReferencedAssemblies.Add(GetZeldaAPIAssembly().Location);

            // Create a C# code provider and compile the code.
            // The 'using' statement is necessary so the created DLL file isn't
            // locked when we try to load its contents.
            using (Microsoft.CSharp.CSharpCodeProvider csProvider = new Microsoft.CSharp.CSharpCodeProvider()) {
                CompilerResults csResult = csProvider.CompileAssemblyFromSource(options, code);
                pathToAssembly = csResult.PathToAssembly;
                hasErrors      = csResult.Errors.HasErrors;

                // Copy warnings and errors into the ScriptComileResult result.
                foreach (CompilerError csError in csResult.Errors)
                {
                    ScriptCompileError error = new ScriptCompileError(csError.Line,
                                                                      csError.Column, csError.ErrorNumber, csError.ErrorText, csError.IsWarning);
                    if (error.IsWarning)
                    {
                        result.Warnings.Add(error);
                    }
                    else
                    {
                        result.Errors.Add(error);
                    }
                }
            }

            // If the compile was successful, then load the created.
            // DLL file into memory and then delete the file.
            if (!hasErrors)
            {
                result.RawAssembly = File.ReadAllBytes(pathToAssembly);
                //rawAssembly = result.RawAssembly;
                File.Delete(pathToAssembly);
            }
            else
            {
                //rawAssembly = null;
            }

            return(result);
        }
コード例 #4
0
        // Compile all the scripts into one assembly.
        public ScriptCompileResult Compile(string code)
        {
            ScriptCompileResult result	= new ScriptCompileResult();
            string pathToAssembly = "";
            bool hasErrors = false;

            // Setup the compile options.
            CompilerParameters options	= new CompilerParameters();
            options.GenerateExecutable	= false;	// We want a Dll (Class Library)
            options.GenerateInMemory	= false;	// Save the assembly to a file.
            options.OutputAssembly		= "ZWD2CompiledScript.dll";

            // Add the assembly references.
            options.ReferencedAssemblies.Add(GetZeldaAPIAssembly().Location);

            // Create a C# code provider and compile the code.
            // The 'using' statement is necessary so the created DLL file isn't
            // locked when we try to load its contents.
            using (Microsoft.CSharp.CSharpCodeProvider csProvider = new Microsoft.CSharp.CSharpCodeProvider()) {
                CompilerResults csResult = csProvider.CompileAssemblyFromSource(options, code);
                pathToAssembly	= csResult.PathToAssembly;
                hasErrors		= csResult.Errors.HasErrors;

                // Copy warnings and errors into the ScriptComileResult result.
                foreach (CompilerError csError in csResult.Errors) {
                    ScriptCompileError error = new ScriptCompileError(csError.Line,
                        csError.Column, csError.ErrorNumber, csError.ErrorText, csError.IsWarning);
                    if (error.IsWarning)
                        result.Warnings.Add(error);
                    else
                        result.Errors.Add(error);
                }
            }

            // If the compile was successful, then load the created.
            // DLL file into memory and then delete the file.
            if (!hasErrors) {
                result.RawAssembly = File.ReadAllBytes(pathToAssembly);
                //rawAssembly = result.RawAssembly;
                File.Delete(pathToAssembly);
            }
            else {
                //rawAssembly = null;
            }

            return result;
        }
コード例 #5
0
ファイル: Script.cs プロジェクト: trigger-death/ZeldaOracle
 public ScriptCompileError(ScriptCompileError copy)
 {
     Line		= copy.Line;
     Column		= copy.Column;
     ErrorNumber	= copy.ErrorNumber;
     ErrorText	= copy.ErrorText;
     IsWarning	= copy.IsWarning;
 }