using System;
using System.Collections.Specialized;
using System.Collections;
using System.IO;
namespace FineUIPro.Web.common
{
public class TemplateHelper
{
///
/// 私有构造方法,不允许创建实例
///
private TemplateHelper()
{
// TODO: Add constructor logic here
}
///
/// Template File Helper
///
/// Templet Path
/// NameValueCollection
/// string
public static string BulidByFile(string templatePath, NameValueCollection values)
{
return BulidByFile(templatePath, values, "[$", "]");
}
///
/// Template File Helper
///
/// Templet Path
/// NameValueCollection
/// string
public static string BulidByFile2(string templatePath, NameValueCollection values)
{
return BulidByFile2(templatePath, values, "[$", "]");
}
///
///
///
///
/// NameValueCollection obj
///
///
///
public static string Build(string template, NameValueCollection values, string prefix, string postfix)
{
if (values != null)
{
foreach (DictionaryEntry entry in values)
{
template = template.Replace(string.Format("{0}{1}{2}", prefix, entry.Key, postfix), entry.Value.ToString());
}
}
return template;
}
///
///
///
///
///
///
///
///
public static string BulidByFile(string templatePath, NameValueCollection values, string prefix, string postfix)
{
StreamReader reader = null;
string template = string.Empty;
try
{
reader = new StreamReader(templatePath);
template = reader.ReadToEnd();
reader.Close();
if (values != null)
{
foreach (string key in values.AllKeys)
{
template = template.Replace(string.Format("{0}{1}{2}", prefix, key, postfix), values[key]);
}
}
}
catch
{
}
finally
{
if (reader != null)
reader.Close();
}
return template;
}
///
///
///
///
///
///
///
///
public static string BulidByFile2(string templatePath, NameValueCollection values, string prefix, string postfix)
{
string template = templatePath;
if (values != null)
{
foreach (string key in values.AllKeys)
{
template = template.Replace(string.Format("{0}{1}{2}", prefix, key, postfix), values[key]);
}
}
return template;
}
}
}