Developer forum

Forum » Development » Items - template extender

Items - template extender

Morten Bengtson
Reply

My current solution where I use SerializeTo/DeserializeFrom in the template extender does not work.

 

using System.Collections.Generic;
using Dynamicweb.Content.Items.Rendering;
using Dynamicweb.Rendering;
 
public class ArticleTemplateExtender : ItemTemplateExtender
{
    public override void ExtendTemplate(Template template)
    {
        var item = this.Item as Dynamicweb.Content.Items.Item;
        if (item == null || !item.SystemName.Equals("Article"))
        {
            return;
        }
 
        var article = new Article();            
        var dictionary = new Dictionary<string, object>();
        this.Item.SerializeTo(dictionary);
        article.DeserializeFrom(dictionary);
 
        // Set tags here
    }
}

 

I have a property of type IList<string>, which works fine when creating and editing items in the administration, but rendering in frontend throws this exception on DeserializeFrom:

 

System.InvalidCastException: Invalid cast from 'System.String' to 'System.Collections.Generic.IList`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.

 

Any suggestions?

 

/Morten

 


Replies

 
Morten Bengtson
Reply

This error was caused by a custom ListEditor that inherited from a non-generic base class. I changed it so that it inherits directly from this...

 

Dynamicweb.Content.Items.Editors.ListEditor<T>


... and now it works fine.
 

 

You must be logged in to post in the forum