Exemple #1
0
 public Plugin(PluginManager _Manager, string _PluginName, string _SourceCode)
 {
     type = PluginManager.CompilerType.CSharp;
     assembly = PluginManager.Compile(_PluginName, _SourceCode, type);
     pluginname = _PluginName;
     source = _SourceCode;
     manager = _Manager;
     if (assembly != null)
     {
         foreach (Type t in assembly.GetTypes())
         {
             Log.Write("Plugin Compiler", "Type compiled {0}", t.FullName);
         }
     }
 }
Exemple #2
0
        public static Assembly Compile(string _AssemblyName, string _Source, PluginManager.CompilerType _Compiler)
        {
            CodeDomProvider compiler = new CSharpCodeProvider();

            CompilerParameters compilerParams = new CompilerParameters();
            compilerParams.GenerateInMemory = true;
            compilerParams.IncludeDebugInformation = true;
            compilerParams.ReferencedAssemblies.Add("system.dll");
            compilerParams.ReferencedAssemblies.Add("synergy.dll");
            compilerParams.GenerateExecutable = true;

            compilerParams.OutputAssembly = string.Format("Binaries/{0}.dll", _AssemblyName);
            CompilerResults results = compiler.CompileAssemblyFromSource(compilerParams, _Source);

            if (results.Errors.Count > 0)
            {
                foreach (CompilerError e in results.Errors)
                {
                    Log.Write("Plugin Compiler", Log.Line.Type.Error, e.ToString());
                }
                return null;
            }
            return results.CompiledAssembly;
        }