Beispiel #1
0
        /// <summary>
        /// Adds script files to this ScriptCollection.
        /// </summary>
        /// <param name="scriptFiles">An IEnumerable of paths to the script files to load into this collection.</param>
        /// <param name="language">Language of the scripts.</param>
        /// <returns>Errors and warnings generated when compiling the scripts.</returns>
        CompilerErrorCollection AddScriptFiles(IEnumerable <string> scriptFiles, ScriptLanguage language)
        {
            // Check for files
            if (scriptFiles == null)
            {
                return(null);
            }

            scriptFiles = scriptFiles.ToImmutable();
            if (scriptFiles.IsEmpty())
            {
                return(null);
            }

            // Get the assembly
            CompilerErrorCollection errors = null;
            var asm = _scriptAssemblyCache.CreateInCache(scriptFiles, x => CompileCode(x, scriptFiles, language, out errors));

            if (asm == null)
            {
                _compilationFailed = true;
            }
            else
            {
                // Add the new types
                var newTypes = asm.GetExportedTypes();
                foreach (var newType in newTypes)
                {
                    _types.Add(newType.Name, newType);
                }
            }

            return(errors);
        }
        /// <summary>
        /// Compiles the source code.
        /// </summary>
        /// <param name="assembly">The created <see cref="Assembly"/>.</param>
        /// <returns>A <see cref="AssemblyClassInvoker"/> to invoke the compiled <see cref="Assembly"/>, or
        /// null if the compilation failed.</returns>
        public virtual AssemblyClassInvoker Compile(out Assembly assembly)
        {
            var sourceCode = GetSourceCode(_members);

            assembly = _scriptAssemblyCache.CreateInCache(sourceCode, x => CompileSourceToAssembly(sourceCode, x));

            if (assembly == null)
            {
                return(null);
            }

            return(CreateAssemblyClassInvoker(assembly, ClassName));
        }