Ejemplo n.º 1
0
        public RazorTemplateCompiler(RazorSourceGenerator sourceGenerator,
                                     RoslynCompilationService roslynCompilationService, TkRazorProject razorLightProject,
                                     TkRazorOptions razorLightOptions)
        {
            TkDebug.AssertArgumentNull(sourceGenerator, nameof(sourceGenerator), null);
            TkDebug.AssertArgumentNull(roslynCompilationService, nameof(roslynCompilationService), null);
            //TkDebug.AssertArgumentNull(razorLightProject, nameof(razorLightProject), null);
            TkDebug.AssertArgumentNull(razorLightOptions, nameof(razorLightOptions), null);

            fRazorSourceGenerator = sourceGenerator;
            fCompiler             = roslynCompilationService;
            fRazorProject         = razorLightProject;
            fRazorLightOptions    = razorLightOptions;

            fNormalizedKeysCache = new ConcurrentDictionary <string, string>(StringComparer.Ordinal);
        }
Ejemplo n.º 2
0
        public virtual IRazorEngine Build()
        {
            var options = new TkRazorOptions();

            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;
            }
            string baseType = string.IsNullOrEmpty(BaseType) ? BASE_TYPE : BaseType;
            //if (CachingProvider != null)
            //    options.CachingProvider = CachingProvider;

            var metadataReferenceManager = new DefaultMetadataReferenceManager(
                options.AdditionalMetadataReferences, options.ExcludedAssemblies);
            var assembly = OperatingAssembly ?? Assembly.GetEntryAssembly();
            var compiler = new RoslynCompilationService(metadataReferenceManager, assembly);

            var sourceGenerator         = new RazorSourceGenerator(DefaultRazorEngine.CreateInstance(baseType), Project, options.Namespaces);
            var templateCompiler        = new RazorTemplateCompiler(sourceGenerator, compiler, Project, options);
            var templateFactoryProvider = new TemplateFactoryProvider();

            var engineHandler = new EngineHandler(options, templateCompiler, templateFactoryProvider);

            return(new TkRazorEngine(engineHandler));
        }