Open GoogleCodeExporter opened 9 years ago
Original comment by paul.wel...@gmail.com
on 20 Sep 2010 at 5:37
Recently I played a bit with your templates and get it worked. That required
changing single template file - CSharp\Entities.cst
You need to make 3 simple steps for that:
1. Add to properties in that file:
<%@ Assembly Name="CodeSmith.CustomProperties" %>
<%@ Import Namespace="CodeSmith.CustomProperties" %>
<%@ Property Category="1.Mapping" Name="CustomResultsMapping"
Type="CodeSmith.CustomProperties.NameValueCollection" Optional="True"
Description="List of pairs (original class name and its desired replacement)"
Default="ComplexSpResult1=ComplexSpResult_Main" %>
2. Somewhere between <script></script> tags:
// look for "CustomResultsMapping" and "SetMappingClassNames" usage in this file
private string GetMappingClassName(string className){
var value = CustomResultsMapping.GetByKey(className);
return value ?? className;
}
private void SetMappingClassNames(Database database){
if (CustomResultsMapping != null) {
foreach (var fn in database.Functions){
foreach (var tp in fn.Types){
tp.Name = GetMappingClassName(tp.Name);
foreach (var stp in tp.SubTypes)
stp.Name = GetMappingClassName(stp.Name);
}
}
}
}
3. Change CreateDataContextClass method as following:
public void CreateDataContextClass(Database database)
{
var t = this.Create<DataContextGeneratedClass>();
this.CopyPropertiesTo( t );
SetMappingClassNames( database );
t.Database = database;
//... rest of method code here
}
That's all. Manage template - add as keys class names you want to change and as
values class names you want to be generated instead.
As a result classes with new names will be generated. Also new class name will
be passed as method attributes.
I've attached also result file here.
Thanks a ton for plinqo!
Original comment by gusen...@gmail.com
on 24 Sep 2010 at 8:23
Attachments:
Original issue reported on code.google.com by
gusen...@gmail.com
on 16 Sep 2010 at 12:51