Skip to content

Instantly share code, notes, and snippets.

@javafun
Forked from kimgunnarsson/FindProperty.cs
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javafun/ea05fe05d8030a09bece to your computer and use it in GitHub Desktop.
Save javafun/ea05fe05d8030a09bece to your computer and use it in GitHub Desktop.
using EPiServer;
using EPiServer.Core;
using EPiServer.ServiceLocation;
namespace Core.Properties
{
public static class PropertyFinder
{
public static T FindProperty<T>(PageData currentPage, string propertyName)
{
if (currentPage[propertyName] != null) {
return (T)currentPage[propertyName];
}
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var parentPage = contentRepository.Get<PageData>(currentPage.ParentLink);
if (parentPage == null) {
return default(T);
}
if (parentPage[propertyName] != null) {
return (T)parentPage[propertyName];
}
return FindProperty<T>(parentPage, propertyName);
}
}
}
private MyPropertyType _myInheritedProperty;
public MyPropertyType MyInheritedProperty
{
get
{
if (_myInheritedProperty == null)
{
_myInheritedProperty = Core.Properties.PropertyFinder.FindProperty<MyPropertyType>(CurrentPage, "MyInheritedProperty");
}
return _myInheritedProperty;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment