|
Hi Joel,
One of the cases I'm encountering more and more when using PageTypeBuilder is the limitation caused by c# singular inheritance, meaning that a lot of my TypedPageData classes contain repeated property definitions.
Scenario:
I have a bunch of common elements that are used across multiple page templates. These elements each require multiple PageTypeProperties.
Page1 contains Element1, Element2
Page2 contains Element2, Element3
Page3 contains Element1, Element3
In simple scenarios this could be achieved using a singular TypedPageData base class, however in the above situation, we can't do that as there isn't a common set of elements between all three pages. This means that I end up with three TypedPageData classes
all of which have multiple definitions for the same property. Extending this scenario further to a more realistic number of templates and it starts to become a bit of a pain.
I actually wonder whether this need is the same as mentioned ion the existing request in the issue tracker
'Read PageTypeProperty attributes from interfaces' - http://pagetypebuilder.codeplex.com/workitem/5708
Reading the discussion on that thread, I think your solution about using interfaces to ensure the necessary properties are implemented by each PageType is sensible. Where you want to change implementations per class this is very flexible, but it still means
some additional work to implement each PageTypeProperty on every TypedPageData class. If you actually want the same implementation and attribute meta-data, you've no option but to repeat your code.
What I was wondering is whether there was a better way, as I'm pretty sure this is a common scenario. My initial thoughts were as to whether we could compose TypedPageData classes from other TypedPageData classes rather than relying on singular inheritance.
[PageType]
public class PageType : TypedPageData
{
[PageTypeProperty]
public string StringProperty { get; set; }
public EmbeddedPageType AnEmbeddedPageType { get; set; }
}
[PageType]
public class EmbeddedPageType : TypedPageData
{
[PageTypeProperty]
public string AnotherStringProperty { get; set; }
}
and PageTypeBuilder discovery could flatten these out to a single definition list containing StringProperty and AnotherStringProperty. Initially I can see a few validation cases that must be handled (property name conflicts for example, circular compositions).
Not too sure about this approach so just wanted to get your opinions before I cracked on with a test implementation.
Thanks
Mark
|