I followed your gist example for using ditto with archetype however I am having some issues. My situation is this:
My poco:
public class GlobalContent
{
public RelatedLinks PrimaryHeaderLinks { get; set; }
public RelatedLinks GlobalSecondaryHeaderLinks { get; set; }
public IEnumerable<MultiBlockContent> GlobalFooterColumns { get; set; }
}
The first 2 properties all map nicely. The second one is MultiblockContent which looks like
[TypeConverter(typeof(MultiBlockContentTypeConvertor))]
public class MultiBlockContent
{
public string BlockLabel { get; set; }
public RelatedLinks BlockContent { get; set; }
}
And the type convertor looks like:
public class MultiBlockContentTypeConvertor : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(ArchetypeModel))
return true;
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is ArchetypeModel)
return ConvertFromArchetype((ArchetypeModel)value);
return base.ConvertFrom(context, culture, value);
}
private MultiBlockContent ConvertFromArchetype(ArchetypeModel value)
{
var fieldset = value.FirstOrDefault();
if (fieldset == null)
return null;
return new MultiBlockContent()
{
BlockLabel = fieldset.GetValue<string>("blockLabel"),
BlockContent = fieldset.GetValue<RelatedLinks>("blockContent")
};
}
}
I know what the issue is which is that the archtype can have multi values. So do I handle this, I guess I need to update code in MultiBlockContentTypeConvertor so it then sends back IEnumerable
Works a treat many thanks, you have a new ditto fan. Anthony was saying we need to start using on all new projects so this is the first one and no doubt the first of many.
Ditto with archtype
Lee,
I followed your gist example for using ditto with archetype however I am having some issues. My situation is this:
My poco:
The first 2 properties all map nicely. The second one is MultiblockContent which looks like
And the type convertor looks like:
I know what the issue is which is that the archtype can have multi values. So do I handle this, I guess I need to update code in MultiBlockContentTypeConvertor so it then sends back IEnumerable
Regards
Ismail
Hi Ismail,
If you move the TypeConverter attribute to the property...
... and remove it from the
MultiBlockContent
class.Then in
MultiBlockContentTypeConvertor.ConvertFromArchetype
you can return a collection/list of items.Hope this helps (so far)?
Cheers,
- Lee
Lee,
Works a treat many thanks, you have a new ditto fan. Anthony was saying we need to start using on all new projects so this is the first one and no doubt the first of many.
Regards
Ismail
Cool, thanks - that's great to hear!!!
Cheers,
- Lee
is working on a reply...