• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Razor.RazorEngineHost类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.Razor.RazorEngineHost的典型用法代码示例。如果您正苦于以下问题:C# RazorEngineHost类的具体用法?C# RazorEngineHost怎么用?C# RazorEngineHost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RazorEngineHost类属于System.Web.Razor命名空间,在下文中一共展示了RazorEngineHost类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: CSharpRazorCodeGenerator

 /// <summary>
 /// Initializes a new instance of the <see cref="CSharpRazorCodeGenerator"/> class.
 /// </summary>
 /// <param name="className">Name of the class.</param>
 /// <param name="rootNamespaceName">Name of the root namespace.</param>
 /// <param name="sourceFileName">Name of the source file.</param>
 /// <param name="host">The host.</param>
 /// <param name="strictMode">Flag to specify that this generator is running in struct mode.</param>
 public CSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host, bool strictMode)
     : base(className, rootNamespaceName, sourceFileName, host)
 {
     StrictMode = strictMode;
     var mvcHost = host as Compilation.RazorEngineHost;
     if (mvcHost != null)
     {
         SetBaseTypeFromHost(mvcHost);
     }
 }
开发者ID:Evgest,项目名称:RazorEngine,代码行数:18,代码来源:CSharpRazorCodeGenerator.cs


示例17: HtmlOptimizerMvc4CSharpRazorCodeGenerator

        public HtmlOptimizerMvc4CSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host, IMinifier minifier)
            : base(className, rootNamespaceName, sourceFileName, host)
        {
            var webPageRazorHost = host as MvcWebPageRazorHost;
              if (webPageRazorHost == null || webPageRazorHost.IsSpecialPage)
            return;
              this.SetBaseType("dynamic");

              _minifier = minifier;
        }
开发者ID:random-username,项目名称:HtmlOptimizerMvc4,代码行数:10,代码来源:HtmlOptimizerMvc4CSharpRazorCodeGenerator.cs


示例18: CSharpRazorBuildProvider

		/// <summary>
		/// Initializes a new instance of the <see cref="CSharpRazorBuildProvider"/> class.
		/// </summary>
		public CSharpRazorBuildProvider()
		{
			this.compilerType = this.GetDefaultCompilerTypeForLanguage("C#");

			this.host = new RazorEngineHost(new CSharpRazorCodeLanguage()) {
				DefaultBaseClass = typeof(ViewPageRef).FullName,
				DefaultNamespace = "RazorOutput",
				DefaultClassName = "ViewPage"
			};
		}
开发者ID:grammarware,项目名称:fodder,代码行数:13,代码来源:src_ServiceStack_Razor_CSharpRazorBuildProvider.cs


示例19: InitializeRazorEngine

 private RazorTemplateEngine InitializeRazorEngine(Type baseClassType, string namespaceOfGeneratedClass, string generatedClassName)
 {
     RazorEngineHost host = new RazorEngineHost(new CSharpRazorCodeLanguage());
     host.DefaultBaseClass = baseClassType.FullName;
     host.DefaultClassName = generatedClassName;
     host.DefaultNamespace = namespaceOfGeneratedClass;
     host.NamespaceImports.Add("System");
     host.NamespaceImports.Add("System.Collections.Generic");
     host.NamespaceImports.Add("System.Linq");
     return new RazorTemplateEngine(host);
 }
开发者ID:jhosm,项目名称:BlissInSoftware.Sandcastle,代码行数:11,代码来源:RazorEngineHostWrapper.cs


示例20: CSharpRazorCodeGenerator

 /// <summary>
 /// Initializes a new instance of the <see cref="CSharpRazorCodeGenerator"/> class.
 /// </summary>
 /// <param name="className">Name of the class.</param>
 /// <param name="rootNamespaceName">Name of the root namespace.</param>
 /// <param name="sourceFileName">Name of the source file.</param>
 /// <param name="host">The host.</param>
 /// <param name="strictMode">Flag to specify that this generator is running in struct mode.</param>
 public CSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host, bool strictMode)
     : base(className, rootNamespaceName, sourceFileName, host)
 {
     StrictMode = strictMode;
     var mvcHost = host as Compilation.RazorEngineHost;
     if (mvcHost != null)
     {
         // set the default model type to "dynamic"
         SetBaseType("dynamic");
     }
 }
开发者ID:JodenSoft,项目名称:JodenSoft,代码行数:19,代码来源:CSharpRazorCodeGenerator.cs



注:本文中的System.Web.Razor.RazorEngineHost类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Razor.RazorTemplateEngine类代码示例发布时间:2022-05-26
下一篇:
C# Profile.ProfileInfoCollection类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap