I have a multilist field on an item that can contain items from different templates. I was wondering if there was any way to map this field in such a way that the objects are mapped to the correct model based on their template. So for example:
public interface IPerson
{
string FullName {get; set;}
}
[SitecoreType(TemplateId="....")]
public class Professor
{
[SitecoreField]
public string Prefix {get; set;}
[SitecoreField]
public string FirstName {get; set;}
[SitecoreField]
public string LastName {get; set;}
public string FullName
{
return string.format("{0} {1} {2}", Prefix, FirstName, LastName)
}
}
[SitecoreType(TemplateId="....")]
public class Student
{
[SitecoreField]
public string FirstName {get; set;}
[SitecoreField]
public string LastName {get; set;}
public string FullName
{
return string.format("{0} {1}", FirstName, LastName)
}
}
[SitecoreType(TemplateId="....")]
public class ClassSession
{
[SitecoreField]
public IEnumerable<IPerson> Participants {get; set;}
}
In this instance I'd like the Participants
property to contain Student
and Professor
objects since they implement the Fullname
property differently.