本文整理汇总了C#中TemplateService.AddNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateService.AddNamespace方法的具体用法?C# TemplateService.AddNamespace怎么用?C# TemplateService.AddNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TemplateService
的用法示例。
在下文中一共展示了TemplateService.AddNamespace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectionList
/// <summary>
/// </summary>
/// <returns></returns>
internal static string ConnectionList()
{
var fileName = FilePath + "\\ConnectionList.htm";
String content;
var stream = new StreamReader(fileName);
content = stream.ReadToEnd();
var connectionList = String.Empty;
foreach (var item in
RuntimeMongoDBContext._mongoConnectionConfigList.Values)
{
if (item.ReplSetName == String.Empty)
{
connectionList += "<li><a href = 'Connection?" + item.ConnectionName + "'>" + item.ConnectionName +
"@" + (item.Host == String.Empty ? "localhost" : item.Host)
+ (item.Port == 0 ? String.Empty : ":" + item.Port) + "</a></li>" +
Environment.NewLine;
}
else
{
connectionList += "<li><a href = 'Connection?" + item.ConnectionName + "'>" + item.ConnectionName +
"</a></li>" + Environment.NewLine;
}
}
var config = new TemplateServiceConfiguration();
//config.ReferenceResolver = (IReferenceResolver)((new UseCurrentAssembliesReferenceResolver()).GetReferences(null));
config.Debug = true;
var ser = new TemplateService(config);
ser.AddNamespace("MongoUtility.Core");
ser.AddNamespace("SystemUtility");
Razor.SetTemplateService(ser);
content = Razor.Parse(content, new {SystemConfig.config.ConnectionList});
return content;
}
示例2: Main
static void Main()
{
string dirsrc = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(Path.Combine(dirsrc, @"..\BBQ"));
using (var service = new TemplateService())
{
service.AddNamespace("test_RazorHandy");
service.GetTemplate(File.ReadAllText(@".\Views\Shared\_L.cshtml"), null, "~/Views/Shared/_L.cshtml");
var result = service.Parse(File.ReadAllText(@".\Views\bbq\Index.cshtml"), new { }, null, "page");
Directory.SetCurrentDirectory(dirsrc);
File.WriteAllText(@".\BBQ_static\index.html", result);
}
}
示例3: AddDefaultNamespacesFromWebConfig
/// <summary>
/// Add the namespaces found in the ASP.NET MVC configuration section of the Web.config file to the provided TemplateService instance.
/// </summary>
private static void AddDefaultNamespacesFromWebConfig(TemplateService templateService)
{
var webConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web.config");
if (!File.Exists(webConfigPath))
return;
var fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = webConfigPath };
var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
var razorConfig = configuration.GetSection("system.web.webPages.razor/pages") as RazorPagesSection;
if (razorConfig == null)
return;
foreach (NamespaceInfo namespaceInfo in razorConfig.Namespaces)
{
templateService.AddNamespace(namespaceInfo.Namespace);
}
}
示例4: AssertAllViewsInAssemblyCanBeCompiled
private void AssertAllViewsInAssemblyCanBeCompiled(Assembly assembly)
{
var config = new TemplateServiceConfiguration();
config.BaseTemplateType = typeof(MvcTemplateBase<>);
var processor = new TemplateService(config);
var resourceNames = assembly.GetManifestResourceNames();
foreach (var resource in resourceNames)
{
if (resource.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase))
{
var content = this.GetEmbeddedViewContent(resource, assembly);
// The namespace for ChildActionExtensions
processor.AddNamespace("System.Web.Mvc.Html");
processor.AddNamespace("System.Web");
this.AssertViewCanBeCompiled(content, resource, processor);
}
}
processor.Dispose();
}