示例#1
0
		private static GeneratorResults GenerateCode(RazorTemplateEntry entry)
		{
			var host = new NodeRazorHost(new CSharpRazorCodeLanguage());

			host.DefaultBaseClass = string.Format("Http.Renderer.Razor.Integration.RazorTemplateBase<{0}>", TypeToString(entry.ModelType));
			host.DefaultNamespace = "Http.Renderer.Razor.Integration";
			host.DefaultClassName = entry.TemplateName + "Template";
			host.NamespaceImports.Add("System");
			host.NamespaceImports.Add("System.Dynamic");
			GeneratorResults razorResult = null;
			using (TextReader reader = new StringReader(entry.TemplateString))
			{
				razorResult = new RazorTemplateEngine(host).GenerateCode(reader);
			}
			return razorResult;
		}
		private void RegisterTemplate(string templateName, string templateString, Type modelType)
		{
			if (templateName == null)
				throw new ArgumentNullException("templateName");
			if (templateString == null)
				throw new ArgumentNullException("templateString");

			_templateItems[templateName] = new RazorTemplateEntry()
			{
				ModelType = modelType ?? typeof(object),
				TemplateString = templateString,
				TemplateName = "Rzr" + Guid.NewGuid().ToString("N"),
				IsNoModel = modelType == null
			};
		}