OK, let me describe the scheme used in NHaml. It might give you some
idea.
1. Declare interface ICompiledView with a single line inside:
string Render();
2. Force the user to give some base class type via ViewBaseType
property of Template compiler:
_templateCompiler.ViewBaseType = typeof(NHamlViewData);
User shall have NHamlViewData in advance and this is a class
containing "variables" for the engine. (Personally I'd prefer to see
here simple class with dictionary mapped to template variables, like
VelocityContext.) There can be another pre-defined class, important
here is only that the type is known to the system.
3. Run type builder (CodeDom) to create a new class derived from base
class and implementing ICompiledView interface
public class Temp_NHamlViewData_ab123e7872e : NHamlViewData,
ICompiledView {...}
4. Instantiate this new class (via Activator in version 1.0, and via
IL generation now).
5. NHaml ends with this, but for my scenario there is still an open
issue, so, another step. NHaml expects NHamlViewData (base class and
data context) self-loaded with data. But for my purposes I need a kind
of properties-filled-at-last-minute. I.e., I need to set some data
after instantiation. And here are 2 ways: (a) NHamlViewData obj =
instance as NHamlViewData; (b) make NHamlViewData just a container
public class NHamlViewData<TViewData> where TViewData : class
{
private TViewData _viewData = null;
public TViewData ViewData
{
get { return _viewData; }
}
public void SetViewData(TViewData viewData)
{
_viewData = viewData;
}
}
6. Finally
string output = instance.Render();
Basically, all the magic is inside Render() implementation. All the
calculations are here. But as I can see, Spark has already have this
part done.
Hope this helps.
P.S. (Disclaimer) I have absolutely no intent to push Spark
development in a particular direction - just feeding your mind :)
> >
http://www.ozcandegirmenci.com/post/2008/02/Create-object-instances-F...
> > > >> >
http://www.justnbusiness.com-Hidequoted text -
>
> > > >> - Show quoted text -- Hide quoted text -
>
> > > - Show quoted text -
>
> --
> Justin Chasehttp://www.justnbusiness.com- Hide quoted text -