System.Web.Compilation.BaseCompiler.CreateProvider C# (CSharp) Method

CreateProvider() static private method

static private CreateProvider ( HttpContext context, string lang, CompilerParameters &par, string &tempdir ) : CodeDomProvider
context HttpContext
lang string
par System.CodeDom.Compiler.CompilerParameters
tempdir string
return System.CodeDom.Compiler.CodeDomProvider
		internal static CodeDomProvider CreateProvider (HttpContext context, string lang, out CompilerParameters par, out string tempdir)
		{
			CodeDomProvider ret = null;
			par = null;
			
			CompilationSection config = (CompilationSection) WebConfigurationManager.GetWebApplicationSection ("system.web/compilation");
			Compiler comp = config.Compilers[lang];
			
			if (comp == null) {
				CompilerInfo info = CodeDomProvider.GetCompilerInfo (lang);
				if (info != null && info.IsCodeDomProviderTypeValid) {
					ret = info.CreateProvider ();
					par = info.CreateDefaultCompilerParameters ();
				}
			} else {
				Type t = HttpApplication.LoadType (comp.Type, true);
				ret = Activator.CreateInstance (t) as CodeDomProvider;

				par = new CompilerParameters ();
				par.CompilerOptions = comp.CompilerOptions;
				par.WarningLevel = comp.WarningLevel;
			}
			tempdir = config.TempDirectory;

			return ret;
		}
		

Same methods

BaseCompiler::CreateProvider ( HttpContext context, string lang, string &compilerOptions, int &warningLevel, string &tempdir ) : CodeDomProvider
BaseCompiler::CreateProvider ( string lang ) : CodeDomProvider
BaseCompiler::CreateProvider ( string lang, string &compilerOptions, int &warningLevel, string &tempdir ) : CodeDomProvider

Usage Example

        public static CompilerResults Compile(string language, string key, string file, ArrayList assemblies, bool debug)
        {
            Cache           cache   = HttpRuntime.InternalCache;
            CompilerResults results = (CompilerResults)cache [cachePrefix + key];

            if (results != null)
            {
                return(results);
            }

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

            object ticket;
            bool   acquired = AcquireCompilationTicket(cachePrefix + key, out ticket);

            try
            {
                Monitor.Enter(ticket);
                results = (CompilerResults)cache [cachePrefix + key];
                if (results != null)
                {
                    return(results);
                }

                CodeDomProvider provider = null;
                int             warningLevel;
                string          compilerOptions;
                string          tempdir;

                provider = BaseCompiler.CreateProvider(language, out compilerOptions, out warningLevel, out tempdir);
                if (provider == null)
                {
                    throw new HttpException("Configuration error. Language not supported: " +
                                            language, 500);
                }
                CodeDomProvider    compiler = provider;
                CompilerParameters options  = GetOptions(assemblies);
                options.IncludeDebugInformation = debug;
                options.WarningLevel            = warningLevel;
                options.CompilerOptions         = compilerOptions;

                TempFileCollection tempcoll    = new TempFileCollection(tempdir, true);
                string             dllfilename = Path.GetFileName(tempcoll.AddExtension("dll", true));
                options.OutputAssembly = Path.Combine(dynamicBase, dllfilename);
                results = compiler.CompileAssemblyFromFile(options, file);
                ArrayList realdeps = new ArrayList(assemblies.Count + 1);
                realdeps.Add(file);
                for (int i = assemblies.Count - 1; i >= 0; i--)
                {
                    string current = (string)assemblies [i];
                    if (Path.IsPathRooted(current))
                    {
                        realdeps.Add(current);
                    }
                }

                string [] deps = (string [])realdeps.ToArray(typeof(string));
                cache.Insert(cachePrefix + key, results, new CacheDependency(deps));
            }
            finally
            {
                Monitor.Exit(ticket);
                if (acquired)
                {
                    ReleaseCompilationTicket(cachePrefix + key);
                }
            }

            return(results);
        }