public virtual RazorLightEngine Build() { //options = options ?? new RazorLightOptions(); var options = new RazorLightOptions(); if (namespaces != null) { options.Namespaces = namespaces; } if (dynamicTemplates != null) { options.DynamicTemplates = dynamicTemplates; } if (metadataReferences != null) { options.AdditionalMetadataReferences = metadataReferences; } if (excludedAssemblies != null) { options.ExcludedAssemblies = excludedAssemblies; } if (prerenderCallbacks != null) { options.PreRenderCallbacks = prerenderCallbacks; } if (cachingProvider != null) { options.CachingProvider = cachingProvider; } options.DisableEncoding = disableEncoding; var metadataReferenceManager = new DefaultMetadataReferenceManager(options.AdditionalMetadataReferences, options.ExcludedAssemblies); var assembly = operatingAssembly ?? Assembly.GetEntryAssembly(); var compiler = new RoslynCompilationService(metadataReferenceManager, assembly); var sourceGenerator = new RazorSourceGenerator(DefaultRazorEngine.Instance, project, options.Namespaces); var templateCompiler = new RazorTemplateCompiler(sourceGenerator, compiler, project, options); var templateFactoryProvider = new TemplateFactoryProvider(); var engineHandler = new EngineHandler(options, templateCompiler, templateFactoryProvider, cachingProvider); return(new RazorLightEngine(engineHandler)); }
public virtual RazorLightEngine Build() { options = options ?? new RazorLightOptions(); project = project ?? new NoRazorProject(); if (namespaces != null) { if (namespaces.Count > 0 && options.Namespaces.Count > 0) { ThrowIfHasBeenSetExplicitly(nameof(namespaces)); } options.Namespaces = namespaces; } if (dynamicTemplates != null) { if (dynamicTemplates.Count > 0 && options.DynamicTemplates.Count > 0) { ThrowIfHasBeenSetExplicitly(nameof(dynamicTemplates)); } options.DynamicTemplates = dynamicTemplates; } if (metadataReferences != null) { if (metadataReferences.Count > 0 && options.AdditionalMetadataReferences.Count > 0) { ThrowIfHasBeenSetExplicitly(nameof(metadataReferences)); } options.AdditionalMetadataReferences = metadataReferences; } if (excludedAssemblies != null) { if (excludedAssemblies.Count > 0 && options.ExcludedAssemblies.Count > 0) { ThrowIfHasBeenSetExplicitly(nameof(excludedAssemblies)); } options.ExcludedAssemblies = excludedAssemblies; } if (prerenderCallbacks != null) { if (prerenderCallbacks.Count > 0 && options.PreRenderCallbacks.Count > 0) { ThrowIfHasBeenSetExplicitly(nameof(prerenderCallbacks)); } options.PreRenderCallbacks = prerenderCallbacks; } if (cachingProvider != null) { if (options.CachingProvider != null) { ThrowIfHasBeenSetExplicitly(nameof(cachingProvider)); } options.CachingProvider = cachingProvider; } if (disableEncoding.HasValue) { if (options.DisableEncoding != null) { ThrowIfHasBeenSetExplicitly(nameof(disableEncoding)); } options.DisableEncoding = options.DisableEncoding ?? disableEncoding ?? false; } else { if (!options.DisableEncoding.HasValue) { options.DisableEncoding = false; } } if (enableDebugMode.HasValue && options.EnableDebugMode.HasValue) { ThrowIfHasBeenSetExplicitly(nameof(enableDebugMode)); } else { options.EnableDebugMode = options.EnableDebugMode ?? enableDebugMode ?? false; } var metadataReferenceManager = new DefaultMetadataReferenceManager(options.AdditionalMetadataReferences, options.ExcludedAssemblies); var assembly = operatingAssembly ?? Assembly.GetEntryAssembly(); var compiler = new RoslynCompilationService(metadataReferenceManager, assembly); var sourceGenerator = new RazorSourceGenerator(DefaultRazorEngine.Instance, project, options.Namespaces); var templateCompiler = new RazorTemplateCompiler(sourceGenerator, compiler, project, options); var templateFactoryProvider = new TemplateFactoryProvider(); var engineHandler = new EngineHandler(options, templateCompiler, templateFactoryProvider, cachingProvider); return(new RazorLightEngine(engineHandler)); }