Faking Dynamic Properties with PageTypeBuilder in EPiServer
When building websites in EPiServer you sometimes want a value of a property to be inherited from the parent page. Previously we used Dynamic Properties to have properties inherited, but when using PageTypeBuilder we are spolied with being able to code all our page type properties programactially in classes. However PageTypeBuilder doesn’t support creating Dynamic Properties, but that doesn’t stop us from creating the same functionality with ordinary properties.
After reading Joel’s blog post about dynamic properties with PageTypeBuilder and trying out the snippets of code he wrote, I decided to convert it into an extension method to make it easier to implement in more properties and projects.
Extension Method
{
if (pageData == null) return null;
if (expression == null) throw new ArgumentException("Missing expression parameter", "expression");
TProperty value = pageData.GetPropertyValue(expression);
if (value == null && pageData.ParentLink != null && pageData.PageLink != PageReference.StartPage) {
var page = DataFactory.Instance.GetPage(pageData.ParentLink) as TPageData;
value = page != null ? expression.Compile()(page) : null;
}
return value;
}
Sample Usage
public string MyInheirtedProperty
{
get { return this.GetFakeDynamicProperty(page => page.MyInheirtedProperty); }
}
If you know any improvements that can be made to this method – please do leave a comment.

Comments
No comments yet.