Esempio n. 1
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));
        }
        public override object Create(string key, params object[] args)
        {
            RazorTemplateCompiler compiler = ObjectUtil.QueryObject <RazorTemplateCompiler>(args);

            return(compiler.CreateDescriptor(key));
        }