PageTypeBuilder – makes developing with EPiServer funny

As you may have noticed over the last month, Joel Abrahamsson has created a module to EPiServer called PageTypeBuilder. In a short explanation PageTypeBuilder brings joy into developing with EPiServer! No more need for ranting around in admin mode, no more need of synchronizing page types between dev – test- stage – live! You get stronged typed access to all properties defined, you can inherit page types, you can also very easy create your own package with page types and reuse it in another project. Anyway, Joel explains it all on his own blog in four different blog posts.

So why am I writing this post when Joel explains it all?

First of all, I want to spread the PageTypeBuilder – I can guarantee that you will enjoy working with EPiServer much much more with this module.

Just a small thing like this code makes me happy.

public T1 GetDefaultPageData<T1>(PageReference parent) where T1 : TypedPageData
int? id = PageTypeResolver.Instance.GetPageTypeID(typeof(T1));
if (!id.HasValue)
throw new Exception("Could not find PageTypeID for class " + typeof(T1).ToString());
return (T1)DataFactory.Instance.GetDefaultPageData(parent, id.Value);

With this code you can create a new page of any page type you have defined with the PageTypeBuilder without having to store the id or the name of the page type in some settings page/web.config. You just need to use this nice line:

MyPageType myPage = GetDefaultPageData<MyPageType>(pageRefParent);

Code snippets

Another reason for writing this post is to say that I’ve updated the code snippets I’ve blogged about earlier.

I’ve added two snippets:

  • pt – which is the attribute for the class
  • ptppage – page reference property

I’ve also updated all the old snippets to include EditCaption and HelpText, so it’s a bit more user friendly now.

You can download the new zip-package here

Unzip the files into “My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets”.