Automatically Load Property Types as Dynamic Content

blog header image

Dynamic Content is cool! Really cool. However, even good things can always get better. Back in october last year I wrote about how to automatically register dynamic content by attaching an attribute (like all other plugins in EPiServer). Now, I’ve extended that project to also include auto registration of all the property types in EPiServer as Dynamic Content.

“Now, why would you do a crazy thing like that?”, you might wonder. The answer comes in two parts: a) I guess I don’t have a life, and b) I’ve noticed that as I grow more and more accustomed to Dynamic Content I’ve started to use it like I would use web parts. That means that I’ve been creating Dynamic Content (DC) wrappers for common EPiServer properties so editors can drag them around xhtml-fields and use them as building blocks.

Anyway, I figured the time was right for a generic way to include all the Property types as Dynamic Content. First, I used generics to create a “PropertyDC<PropertyType> : IDynamicContent” class, secondly I made sure that one of those were registrered upon startup for every Property Type in EPiServer CMS.

foreach (PageDefinitionType pdf in PageDefinitionType.List())
{
    //We now have a property type
        
    PropertyData pd=(pdf.TypeName==null) ?
        PropertyData.CreatePropertyDataObject(pdf.DataType)
        :
        PropertyData.CreatePropertyDataObject(pdf.AssemblyName, pdf.TypeName);
    
    
    Type basetype=typeof(PropertyDC<>);
    Type result = basetype.MakeGenericType(pd.GetType());
    AddNewDC("[Property] "+pdf.Name, result, pdf.TypeName);
}
Recent posts