惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
A
About on SuperTechFans
博客园 - Franky
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
B
Blog
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
Martin Fowler
Martin Fowler
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 叶小钗
Vercel News
Vercel News
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
Last Week in AI
Last Week in AI
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
V
V2EX
G
Google Developers Blog

博客园 - 文's sky

泛型列表(List)的搜索和排序 [笔记]读取含日期格式的记录SQLite报错"该字符串未被识别为有效的 DateTime"的问题 FtpWebRequest 的杂症 - "The server committed a protocol violation","基础连接已经关闭: 服务器提交了协议冲突" SqlServer 2000默认开启连接池 设计模式学习系列-C#的单件模式 ASP 整合ASP.NET的URL参数编码问题 - 文's sky 序列化遇到"不应有的节点" 转换链接的正则 一、NVelocity介绍 NVelocity开篇 准确计算时间差 EXPLORER自动连接221.5.250.163 ASP.NET C# 验证码 支持中文 噪点 弯曲 [笔记]DataView格式化显示数据不能的问题 .Net论坛,让人看笑话~ 实在受不了了,大家来帮帮我如何调用这个C++/CLI的DLL C#外挂专用截取显示器图像代码 C#游戏外挂代码 重置递增号
模板机制的第一个程序Hello World
文's sky · 2007-12-04 · via 博客园 - 文's sky

很简单,但是终于还是弄出来了~
用的StringTemplate模板引擎~原本模板是写在.cs里面的,分离出来之后感觉速度慢了不少....估计要缓存吧~不知道还有更好的建议没有

模板页

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    
<head>
        
<title>$title$</title>
    
</head>
    
<body>
        $var$
    
</body>
</html>

.aspx页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TemplateTest._Default" %>

.cs页面

using System;
using System.Web;
using Antlr.StringTemplate;
using System.IO;
//using Antlr.StringTemplate.Language;
//using antlr.collections;

namespace TemplateTest
{
    
public partial class _Default : System.Web.UI.Page
    {
        
protected void Page_Load(object sender, EventArgs e)
        {
            StringTemplate st 
= new StringTemplate(Read("default.htm"));
            st.SetAttribute(
"title""第一个示例");
            st.SetAttribute(
"var""Hello World");
            Response.Write(st.ToString());
        }
public static string Read(string filename)
        {

            filename 

= HttpContext.Current.Server.MapPath("~/Template/" + filename);
            
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                StreamReader sr 
= new StreamReader(fs);
                
return sr.ReadToEnd();
            }

        }

    }
}

还有效果图