當前位置: 首頁>>代碼示例>>C#>>正文


C# Razor.RazorEngineHost類代碼示例

本文整理匯總了C#中System.Web.Razor.RazorEngineHost的典型用法代碼示例。如果您正苦於以下問題:C# RazorEngineHost類的具體用法?C# RazorEngineHost怎麽用?C# RazorEngineHost使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RazorEngineHost類屬於System.Web.Razor命名空間,在下文中一共展示了RazorEngineHost類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: parse

        public static ParsedTemplate parse(string sourceFilename, string cshtmlContent, string effectiveTemplateClassName, Type modelType)
        {
            var csCodeLanguage = new CSharpRazorCodeLanguage();
            var templateHost = new RazorEngineHost(csCodeLanguage, () => new HtmlMarkupParser());

            var concreteBaseClassType = getBaseClassTypeFromModel(modelType);
            templateHost.DefaultBaseClass = concreteBaseClassType.FullName;

            var templateEngine = new RazorTemplateEngine(templateHost);

            var trimmedcshtmlContent = HeaderLines.trim(cshtmlContent);

            GeneratorResults res;
            using (var input = new StringReader(trimmedcshtmlContent))
            {
                res = templateEngine.GenerateCode(input, effectiveTemplateClassName, GeneratedTemplateNamespace, sourceFilename);
            }

            if (!res.Success)
                throw new Exception("Failed to generate code");

            var compileUnit = res.GeneratedCode;
            var fullyQualifiedClassName = GeneratedTemplateNamespace + "." + effectiveTemplateClassName;

            return new ParsedTemplate(fullyQualifiedClassName, compileUnit);
        }
開發者ID:pragmatrix,項目名稱:SiteSharper,代碼行數:26,代碼來源:TemplateParser.cs

示例2: BackgroundParser

        public BackgroundParser(RazorEngineHost host, string fileName)
        {
            _main = new MainThreadState(fileName);
            _bg = new BackgroundThread(_main, host, fileName);

            _main.ResultsReady += (sender, args) => OnResultsReady(args);
        }
開發者ID:RainsSoft,項目名稱:playscript-monodevelop,代碼行數:7,代碼來源:BackgroundParser.cs

示例3: SimpleCSharpRazorCodeGenerator

 public SimpleCSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host)
     : base(className, rootNamespaceName, sourceFileName, host)
 {
     var baseType = new CodeTypeReference(SimpleRazorConfiguration.BaseClass);
     Context.GeneratedClass.BaseTypes.Clear();
     Context.GeneratedClass.BaseTypes.Add(baseType);
 }
開發者ID:muratbeyaztas,項目名稱:Simple.Web,代碼行數:7,代碼來源:SimpleCSharpRazorCodeGenerator.cs

示例4: SimpleCSharpRazorCodeGenerator

 public SimpleCSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host)
     : base(className, rootNamespaceName, sourceFileName, host)
 {
     var baseType = new CodeTypeReference("SimpleTemplateModelBase<dynamic>");
     Context.GeneratedClass.BaseTypes.Clear();
     Context.GeneratedClass.BaseTypes.Add(baseType);
 }
開發者ID:rkevinstout,項目名稱:Simple.Web,代碼行數:7,代碼來源:SimpleCSharpRazorCodeGenerator.cs

示例5: GenerateCode

        private static GeneratorResults GenerateCode(RazorTemplateEntry entry, Type baseType)
        {
            var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
            host.DefaultBaseClass = baseType.FullName;
            host.DefaultNamespace = "TeamConfig.Razor.Template";
            host.DefaultClassName = entry.TemplateName + "Template";
            host.NamespaceImports.Add("System");

            //filter out page directives and add them as namespace
            string templateString = entry.TemplateString;
            foreach (Match match in PageDirectivePattern.Matches(templateString))
            {
                string usedNamespace = match.Groups["Namespace"].Value;
                templateString = templateString.Replace(match.Value, string.Empty);
                if (usedNamespace.StartsWith("using"))
                {
                    host.NamespaceImports.Add(usedNamespace);
                }
            }

            GeneratorResults razorResult = null;

            using (TextReader reader = new StringReader(templateString))
            {
                var templateEngine = new RazorTemplateEngine(host);
                razorResult = templateEngine.GenerateCode(reader);
            }
            return razorResult;
        }
開發者ID:mmanela,項目名稱:TeamConfig,代碼行數:29,代碼來源:Compiler.cs

示例6: Engine

 public Engine()
 {
     _host = new RazorEngineHost(new CSharpRazorCodeLanguage());
     _host.DefaultBaseClass = "MiniMvc.ViewBase";
     //_host.GeneratedClassContext = new System.Web.Razor.Generator.GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo", "something", "DefineSection", "BeginContext", "EndContext");
     _host.GeneratedClassContext = new System.Web.Razor.Generator.GeneratedClassContext("Execute", "Write", "WriteLiteral", null, null, null, "DefineSection", null, null);
 }
開發者ID:nirdobovizki,項目名稱:MiniMvc,代碼行數:7,代碼來源:Engine.cs

示例7: Compile

        public Type Compile(string className, CodeCompileUnit codeCompileUnit, RazorEngineHost host)
        {
            var compilerParameters = new CompilerParameters {GenerateInMemory = true, CompilerOptions = "/optimize"};
            AppDomain.CurrentDomain.GetAssemblies()
                .Where(x => !x.IsDynamic)
                .Each(x => compilerParameters.ReferencedAssemblies.Add(x.Location));

            CompilerResults compilerResults;
            using (var codeDomProvider = Activator.CreateInstance(host.CodeLanguage.CodeDomProviderType).As<CodeDomProvider>())
            {
                compilerResults = codeDomProvider.CompileAssemblyFromDom(compilerParameters, codeCompileUnit);
                if (compilerResults.Errors.HasErrors)
                {
                    using (var sw = new StringWriter())
                    using (var tw = new IndentedTextWriter(sw, "    "))
                    {
                        codeDomProvider.GenerateCodeFromCompileUnit(codeCompileUnit, tw, new CodeGeneratorOptions());
                        var source = sw.ToString();
                        throw CreateExceptionFromCompileError(compilerResults, source);
                    }
                }
            }

            var templateTypeName = "{0}.{1}".ToFormat(host.DefaultNamespace, className);
            var templateType = compilerResults.CompiledAssembly.GetType(templateTypeName);
            return templateType;
        }
開發者ID:uluhonolulu,項目名稱:Chpokk,代碼行數:27,代碼來源:TemplateCompiler.cs

示例8: HtmlMinifierMvcCSharpRazorCodeGenerator

 public HtmlMinifierMvcCSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName,
     RazorEngineHost host, IHtmlPageMinifier htmlPageMinifier, IDebugStatusReader debugStatusReader)
     : base(className, rootNamespaceName, sourceFileName, host)
 {
     m_HtmPagelMinifier = htmlPageMinifier;
     m_DebugStatusReader = debugStatusReader;
 }
開發者ID:LaboFoundation,項目名稱:Labo.WebSiteOptimizer,代碼行數:7,代碼來源:HtmlMinifierMvcCSharpRazorCodeGenerator.cs

示例9: MvcCSharpRazorCodeGenerator

 public MvcCSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host)
     : base(className, rootNamespaceName, sourceFileName, host)
 {
     // set the default model type to "dynamic" (Dev10 bug 935656)
     // don't set it for "special" pages (such as "_viewStart.cshtml")
     SetBaseType(DefaultModelTypeName);
 }
開發者ID:464884492,項目名稱:Mvc,代碼行數:7,代碼來源:MvcCSharpRazorCodeGenerator.cs

示例10: ParseToCode

 public GeneratorResults ParseToCode(string TemplateCode, string defaultnamespace, string defaultclassname, string baseClassFullName)
 {
     GeneratorResults razorResults;
     var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
     host.DefaultBaseClass = baseClassFullName;//typeof(BulaqTemplateForRazorBase).FullName;
     host.DefaultNamespace = defaultnamespace;
     host.DefaultClassName = defaultclassname;
     host.NamespaceImports.Add("System");
     host.NamespaceImports.Add("BulaqCMS.Models");
     host.GeneratedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral");
     var engine = new RazorTemplateEngine(host);
     using (var reader = new StringReader(TemplateCode))
     {
         razorResults = engine.GenerateCode(reader);
         CSharpCodeProvider codeProvider = new CSharpCodeProvider();
         CodeGeneratorOptions options = new CodeGeneratorOptions();
         options.BracingStyle = "C";
         using (StringWriter writer = new StringWriter())
         {
             IndentedTextWriter indentwriter = new IndentedTextWriter(writer, "    ");
             codeProvider.GenerateCodeFromCompileUnit(razorResults.GeneratedCode, indentwriter, options);
             indentwriter.Flush();
             indentwriter.Close();
             LastGeneratedCode = writer.GetStringBuilder().ToString();
             string codePath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\code.cs";
             File.WriteAllText(codePath, LastGeneratedCode, Encoding.UTF8);
         }
     }
     return razorResults;
 }
開發者ID:abduwaris,項目名稱:BulaqCMS,代碼行數:30,代碼來源:RazorTemplateParser.cs

示例11: ReadBlockSpans

 void ReadBlockSpans(string markup)
 {
     var razorEngineHost = new RazorEngineHost(codeLanguage);
     var engine = new RazorTemplateEngine(razorEngineHost);
     var results = engine.ParseTemplate(new StringReader(markup));
     spans = new List<Span>(results.Document.Flatten());
     spans.RemoveAll(span => !span.IsBlock);
 }
開發者ID:RazorPad,項目名稱:RazorPad,代碼行數:8,代碼來源:RazorSpans.cs

示例12: ReadHtmlSpans

		void ReadHtmlSpans(string html)
		{
			RazorEngineHost razorEngineHost = new RazorEngineHost(codeLanguage);
			RazorTemplateEngine engine = new RazorTemplateEngine(razorEngineHost);
			ParserResults results = engine.ParseTemplate(new StringReader(html));
			spans = new List<Span>(results.Document.Flatten());
			spans.RemoveAll(span => span.Kind != SpanKind.Markup);
		}
開發者ID:nylen,項目名稱:SharpDevelop,代碼行數:8,代碼來源:RazorHtmlSpans.cs

示例13: SimpleRazorBuildProvider

 public SimpleRazorBuildProvider()
 {
     this._codeLanguage = new CSharpRazorCodeLanguage();
     this._compilerType = GetDefaultCompilerTypeForLanguage(this._codeLanguage.LanguageName);
     this._host = new SimpleRazorEngineHost(this._codeLanguage);
     this._virtualPathDependencies = null;
     this._typeName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", this._host.DefaultNamespace, "Foot");
 }
開發者ID:muratbeyaztas,項目名稱:Simple.Web,代碼行數:8,代碼來源:SimpleRazorBuildProvider.cs

示例14: MvcCSharpRazorCodeGenerator

 public MvcCSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host)
     : base(className, rootNamespaceName, sourceFileName, host) {
     var mvcHost = host as MvcWebPageRazorHost;
     if (mvcHost != null && !mvcHost.IsSpecialPage) {
         // set the default model type to "dynamic" (Dev10 bug 935656)
         // don't set it for "special" pages (such as "_viewStart.cshtml")
         SetBaseType(_defaultModelTypeName);
     }
 }
開發者ID:adrianvallejo,項目名稱:MVC3_Source,代碼行數:9,代碼來源:MvcCSharpRazorCodeGenerator.cs

示例15: RazorTemplateEngine

        /// <summary>
        /// Constructs a new RazorTemplateEngine with the specified host
        /// </summary>
        /// <param name="host">The host which defines the environment in which the generated template code will live</param>
        public RazorTemplateEngine(RazorEngineHost host)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            Host = host;
        }
開發者ID:KevMoore,項目名稱:aspnetwebstack,代碼行數:13,代碼來源:RazorTemplateEngine.cs


注:本文中的System.Web.Razor.RazorEngineHost類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。