Exemple #1
0
        ////////////////////////////////////////////////////////////////
        // Constructors
        ////////////////////////////////////////////////////////////////

        public CompiledUnit(SourceUnitSpecification specification, string scriptFileName, string[] referencedAssemblies, Error[] errors)
        {
            this.methods = new Dictionary <string, CompiledMethodWrapper>();

            this.ReferencedAssemblies = referencedAssemblies;
            this.specification        = specification;
            this.ScriptFileName       = scriptFileName;
            this.Errors = errors;
        }
Exemple #2
0
        ////////////////////////////////////////////////////////////////
        // Constructors
        ////////////////////////////////////////////////////////////////

        public SourceUnitCompiler(string tempDir, SourceUnitSpecification sourceSpec)
        {
            this.sourceSpec = sourceSpec;
            this.tempDir    = tempDir;

            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }

            this.tempDir2 = tempDir;
            if (!this.tempDir2.EndsWith("" + Path.DirectorySeparatorChar))
            {
                this.tempDir2 += Path.DirectorySeparatorChar;
            }

            csharpCompiler = CSharpCodeProvider.CreateProvider("cs");

            codeGenList = new CodeGenList();

            this.AssemblyManager = new AssemblyManager();
        }
Exemple #3
0
        public CompiledUnit(SourceUnitSpecification specification,
                            string scriptFileName, string[] referencedAssemblies, Assembly compiledAssembly, Type compiledClass)
        {
            this.methods = new Dictionary <string, CompiledMethodWrapper>();

            this.ReferencedAssemblies = referencedAssemblies;
            this.specification        = specification;
            this.ScriptFileName       = scriptFileName;
            this.Errors           = new Error[0];
            this.compiledAssembly = compiledAssembly;

            ConstructorInfo ci = compiledClass.GetConstructor(Type.EmptyTypes);

            if (ci == null)
            {
                throw new InvalidOperationException(
                          "Unable to compile scripts: No empty constructor defined within class based on " + scriptFileName + "!");
            }
            scriptObj = ci.Invoke(new object[0]);

            foreach (MethodSpecification m in specification.MethodSpecs)
            {
                if (methods.ContainsKey(m.Name))
                {
                    throw new Exception("Method overloading not supported!");
                }

                MethodInfo methodInfo = compiledClass.GetMethod(m.Name, BindingFlags.Public | BindingFlags.Instance);
                if (methodInfo == null)
                {
                    throw new InvalidOperationException(
                              "Unable to compile scripts: Method '" + m.Name + "' not found within class based on " + scriptFileName + "!");
                }

                methods.Add(m.Name, new CompiledMethodWrapper(scriptFileName, scriptObj, compiledClass, m, methodInfo));
            }
        }