public virtual object CreateInstance() { TemplateControl control = (TemplateControl)HttpRuntime.FastCreatePublicInstance(this._baseType); control.TemplateControlVirtualPath = base.VirtualPath; control.TemplateControlVirtualDirectory = base.VirtualPath.Parent; control.SetNoCompileBuildResult(this); return(control); }
internal static System.Web.Compilation.ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host) { if (expressionPrefix.Length == 0) { if (dataBindingExpressionBuilder == null) { dataBindingExpressionBuilder = new DataBindingExpressionBuilder(); } return(dataBindingExpressionBuilder); } CompilationSection compilationConfig = null; if (host != null) { IWebApplication application = (IWebApplication)host.GetService(typeof(IWebApplication)); if (application != null) { compilationConfig = application.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection; } } if (compilationConfig == null) { compilationConfig = MTConfigUtil.GetCompilationConfig(virtualPath); } System.Web.Configuration.ExpressionBuilder builder = compilationConfig.ExpressionBuilders[expressionPrefix]; if (builder == null) { throw new HttpParseException(System.Web.SR.GetString("InvalidExpressionPrefix", new object[] { expressionPrefix })); } Type c = null; if (host != null) { ITypeResolutionService service = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); if (service != null) { c = service.GetType(builder.Type); } } if (c == null) { c = builder.TypeInternal; } if (!typeof(System.Web.Compilation.ExpressionBuilder).IsAssignableFrom(c)) { throw new HttpParseException(System.Web.SR.GetString("ExpressionBuilder_InvalidType", new object[] { c.FullName })); } return((System.Web.Compilation.ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(c)); }
internal CompilerResults Compile() { if ((this._sourceFiles.Count == 0) && (this._embeddedResourceFiles == null)) { return(null); } if (this._objectFactoryGenerator != null) { this._miscCodeCompileUnit = this._objectFactoryGenerator.CodeCompileUnit; } this.AddAssemblyCultureAttribute(); this.AddAspNetGeneratedCodeAttribute(); this.AddAllowPartiallyTrustedCallersAttribute(); this.AddAssemblyDelaySignAttribute(); this.AddAssemblyKeyFileAttribute(); this.AddAssemblyKeyContainerAttribute(); this.AddSecurityRulesAttribute(); this.AddTargetFrameworkAttribute(); this.GenerateMiscCodeCompileUnit(); CompilerParameters compilerParameters = this.GetCompilerParameters(); string[] array = new string[this._sourceFiles.Count]; this._sourceFiles.CopyTo(array, 0); PerfCounters.IncrementCounter(AppPerfCounter.COMPILATIONS); WebBaseEvent.RaiseSystemEvent(this, 0x3eb); HttpContext current = HttpContext.Current; if ((current != null) && EtwTrace.IsTraceEnabled(5, 1)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_COMPILE_ENTER, current.WorkerRequest); } CompilerResults results = null; try { try { using (new ProcessImpersonationContext()) { results = this._codeProvider.CompileAssemblyFromFile(compilerParameters, array); } } finally { if (EtwTrace.IsTraceEnabled(5, 1) && (current != null)) { string str2; string str = null; if (this._buildProviders.Count < 20) { IDictionaryEnumerator enumerator = this._buildProviders.GetEnumerator(); while (enumerator.MoveNext()) { if (str != null) { str = str + ","; } str = str + enumerator.Key; } } else { str = string.Format(CultureInfo.InstalledUICulture, System.Web.SR.Resources.GetString("Etw_Batch_Compilation", CultureInfo.InstalledUICulture), new object[] { this._buildProviders.Count }); } if ((results != null) && ((results.NativeCompilerReturnValue != 0) || results.Errors.HasErrors)) { str2 = System.Web.SR.Resources.GetString("Etw_Failure", CultureInfo.InstalledUICulture); } else { str2 = System.Web.SR.Resources.GetString("Etw_Success", CultureInfo.InstalledUICulture); } EtwTrace.Trace(EtwTraceType.ETW_TYPE_COMPILE_LEAVE, current.WorkerRequest, str, str2); } } } catch { throw; } Type assemblyPostProcessorTypeInternal = this._compConfig.AssemblyPostProcessorTypeInternal; if (assemblyPostProcessorTypeInternal != null) { using (IAssemblyPostProcessor processor = (IAssemblyPostProcessor)HttpRuntime.FastCreatePublicInstance(assemblyPostProcessorTypeInternal)) { processor.PostProcessAssembly(results.PathToAssembly); } } WebBaseEvent.RaiseSystemEvent(this, 0x3ec); if (results == null) { return(results); } this.InvalidateInvalidAssembly(results, compilerParameters); this.FixUpLinePragmas(results); if (results.Errors.HasErrors) { foreach (System.Web.Compilation.BuildProvider provider in this.BuildProviders) { provider.ProcessCompileErrors(results); } } if (BuildManager.CBMCallback != null) { foreach (CompilerError error in results.Errors) { BuildManager.CBMCallback.ReportCompilerError(error); } } if ((results.NativeCompilerReturnValue == 0) && !results.Errors.HasErrors) { return(results); } PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_COMPILING); PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_TOTAL); throw new HttpCompileException(results, this.GetErrorSourceFileContents(results)); }
internal static object CreateObjectFromType(Type type) { return(HttpRuntime.FastCreatePublicInstance(type)); }
internal static object CreateObjectInstance(Type type) { // FastCreatePublicInstance is faster than Activator.CreateInstance since it caches the type factories. return(HttpRuntime.FastCreatePublicInstance(type)); }
internal static ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host) { // If there is no expressionPrefix, it's a v1 style databinding expression if (expressionPrefix.Length == 0) { if (dataBindingExpressionBuilder == null) { dataBindingExpressionBuilder = new DataBindingExpressionBuilder(); } return(dataBindingExpressionBuilder); } CompilationSection config = null; // If we are in the designer, we need to access IWebApplication config instead #if !FEATURE_PAL // FEATURE_PAL does not support designer-based features if (host != null) { IWebApplication webapp = (IWebApplication)host.GetService(typeof(IWebApplication)); if (webapp != null) { config = webapp.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection; } } #endif // !FEATURE_PAL // If we failed to get config from the designer, fall back on runtime config always if (config == null) { config = MTConfigUtil.GetCompilationConfig(virtualPath); } System.Web.Configuration.ExpressionBuilder builder = config.ExpressionBuilders[expressionPrefix]; if (builder == null) { throw new HttpParseException(SR.GetString(SR.InvalidExpressionPrefix, expressionPrefix)); } Type expressionBuilderType = null; if (host != null) { // If we are in the designer, we have to use the type resolution service ITypeResolutionService ts = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); if (ts != null) { expressionBuilderType = ts.GetType(builder.Type); } } if (expressionBuilderType == null) { expressionBuilderType = builder.TypeInternal; } Debug.Assert(expressionBuilderType != null, "expressionBuilderType should not be null"); if (!typeof(ExpressionBuilder).IsAssignableFrom(expressionBuilderType)) { throw new HttpParseException(SR.GetString(SR.ExpressionBuilder_InvalidType, expressionBuilderType.FullName)); } ExpressionBuilder expressionBuilder = (ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(expressionBuilderType); return(expressionBuilder); }