-2
當我調用這個方法時,內存會增加(1M-3M):engine.ProcessTemplate(inputTemplate,host)。我不知道爲什麼?爲什麼內存會增加(t4模板)
注:我使用t4模板生成代碼。
這是我的代碼:
Engine engine = new Engine();
host.Session = new TextTemplatingSession();
Parameter nameSpaceParameter = new Parameter() { Text = "NameSpace", Value = this.txtNameSpaceRoot.Text };//+ strTmp.Replace("Templates." + this.CurSelectedNode.DisplayName, string.Empty)
host.Session.Add("NameSpace", nameSpaceParameter);
Parameter tableNameParameter = new Parameter() { Text = "TableName", Value = oName.Substring(2)};
host.Session.Add("TableName", tableNameParameter);
string inputTemplate = File.ReadAllText(host.TemplateFileValue);
string content=engine.ProcessTemplate(inputTemplate, host);
這是我的T4模板文件:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
<#@ parameter name="NameSpace" type="SmartCodeGenerator.Parameter" #>
<#@ parameter name="TableName" type="SmartCodeGenerator.Parameter" #>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using <#=NameSpace.Value#>.DAL;
using <#=NameSpace.Value#>.Model;
namespace <#=NameSpace.Value#>.BLL
{
public class <#=TableName.Value#>Repository
{
RepositoryBase<<#=TableName.Value#>Model> repository = null;
public <#=TableName.Value#>Repository()
{
repository = new RepositoryBase<<#=TableName.Value#>Model>();
}
#region IRepository<T> 成員
public <#=TableName.Value#>Model Create()
{
return repository.Create();
}
public <#=TableName.Value#>Model Update(<#=TableName.Value#>Model entity)
{
return repository.Update(entity);
}
public <#=TableName.Value#>Model Insert(<#=TableName.Value#>Model entity)
{
return repository.Insert(entity);
}
public void Delete(<#=TableName.Value#>Model entity)
{
repository.Delete(entity);
}
public IList<<#=TableName.Value#>Model> FindAll()
{
return repository.FindAll();
}
public List<<#=TableName.Value#>Model> QueryByPage<TKey>(Expression<Func<<#=TableName.Value#>Model, bool>> filter, Expression<Func<<#=TableName.Value#>Model, TKey>> orderby, int OrderType, int Take, int Skip, out int recordsCount)
{
recordsCount = repository.Query(filter).Count();
if (OrderType == 0)
{
return repository.Query(filter).OrderBy(orderby).Take(Take).Skip(Skip).ToList();
}
else
{
return repository.Query(filter).OrderByDescending(orderby).Take(Take).Skip(Skip).ToList();
}
}
#endregion
}
}
請原諒我的無知,但增加3MB的內存消耗真的很重要嗎?你能否進一步解釋你的情況? – 2012-07-05 10:13:28
我同意@IlianPinzon,3MB不算什麼!我的樹莓派甚至獲得了80塊。 – leppie 2012-07-05 11:58:41