I'm just starting to wade thru CodeSmith, CSLA, and templates. One thing that puzzles me is the "Delegation Methods" region, which apparently was added to support partial classes. That seems like a lot of additional complexity to support a partial class. Is it worth it? Any alternative? :)
The code is in generated class and not in user class, so the amount of code is actually hidden from user.
I toyed whith several alternatives such as adding base class, and creating template methods on user class. This I think is the most elegant way. I also found from one of Eric Gunnerson's article (and test it) that delegates in .Net 2.0 is as performant or close to overrides.
As whether is worth it? That should be my line of question I guess I let others who uses partial class methods to chime in.
Ricky
one disadvantage of code generation with partial classes is that you cannot override methods in de 'Generated' partial class.
With partial class you can't override it but you'll wire delegate with your method contain your overridable code and return false so the generated code won't execute.
======== generated code ===========
private void ExecuteInsert(SqlConnection cn, RootObject parent)
{
if (!onExecuteInsert(cn, parent)) return;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "AddProduct";
AddInsertParameters(cm, parent);
cm.ExecuteNonQuery();
_productID = (int)cm.Parameters["@NewProductID"].Value;
onExecuteInsertComplete(cm, parent);
}//using
}
========== User Code ===========
private bool executeInsert(SqlConnection cn, RootObject parent)
{
//your overridable code goes here
return false; //false when you want to stop executing generated code
}
HTH,
Ricky
Ricky, can you give me an example of why I would need to override a method in the generated class?
Still trying to decide which way to go -- partial or split base
Dave
Copyright (c) Marimer LLC