Tuesday, January 09, 2007

Template Dependencies

So I decided to implement a template dependency system. The idea is that templates are sometimes dependent on other templates so rather than just having the whole thing blowup whenever the dependent template does not implement something I decided to create interfaces that would act as "contracts" between templates. So for example the EntityInfoTemplate implements the IInfoObject contract interface, which has the signature:

namespace NBusiness.Templates.Contracts
public interface IInfoObject
CodeMemberMethod GetInfoObjectMethod(Entity entity);

CodeMemberMethod ToInfoArrayMethod(Entity entity);

And since the EntityBaseTemplate is dependent on the presence of the EntityInfoTemplate in order to implement the GetInfoObject() method it can now use the Dependency.GetContract( ... ) method to determine if the EntityInfo template was assigned to the given entity and if that template implements the IEntityInfo method as required. So in templates where a template is dependent on an entity to have certain other methods/fields/properties/classes you can use the Dependency object. For example:

#region Create GetInfoObject
protected virtual void CreateGetInfoObject(Entity entity, CodeTypeDeclaration Declaration)
IInfoObject getInfoObject = (IInfoObject)Dependency.GetContract("EntityInfo", typeof(IInfoObject), entity);
if(getInfoObject != null)
CodeMemberMethod m = getInfoObject.GetInfoObjectMethod(entity);
OnWarning(new TemplateWarning(
this.GetType().GetMethod("CreateGetInfoObject", BindingFlags.NonPublic BindingFlags.Instance),


Post a Comment

Links to this post:

Create a Link

<< Home