Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ian Robinson 79 posts 143 karma points
    Mar 22, 2012 @ 11:31
    Ian Robinson
    0

    Creating an object data type with the UserControlWrapper

    Hi,

    I need to create my own datatype and I've read the following articles that have allowed me to get started, but in these examples a List<string> is serialized to XML and stored in Umbraco.  I need to store a List<object> where object is my own custom class.

    http://www.nibble.be/?p=24

    http://www.nibble.be/?p=100

    I'm trying to create a multiple choice "Question" document type that has question text as a property and then multiple possible answers, some will be be marked as correct and some will be incorrect.  It's the answer part that I want to create as a custom datatype that will sit in my Question document type. 

    The sample source code from http://www.nibble.be/?p=100 is almost exactly what I need but I don't understand how I could serialize and store a custom answer class with two properties, a string "answer" property and a boolean "isCorrect" property.  The source code stores a List of strings.

    Has anyone come across a tutorial or blog post that demonstrates this type of approach, or can anyone offer some help?

     

  • Rodion Novoselov 694 posts 859 karma points
    Mar 22, 2012 @ 19:50
    Rodion Novoselov
    0

    Hi. List<object> can be serialised-deserialised without problems providing several conditions. Each element of the list should be XML-serialisable itself (i.e. has a public type + a public parameterless constructor) and also the types of the elements should be made known to the serialiser in advance while creating it, e.g.:

    var xmlSerializer = new XmlSerializer(typeof(List<object>), new [] { typeof(ElementType1), typeof(ElementType2) });

     

Please Sign in or register to post replies

Write your reply to:

Draft