Here is an example of using Ditto to map an Archetype property to custom POCO model/type.
Let's say that we have an Archetype to represent some SEO meta-data, and we'll call the DocType property "metaData".
We'd have 3 properties in the Archetype:
- metaTitle
- metaDescription
- metaKeywords
Then for our MyPoco POCO that we'd like to map to our content-node (DocumentType), we would have a property called MetaData (of a custom class/type also called MetaData).
Special note: On the custom class/type
MetaData, we used theTypeConverterattribute to declare the custom converter. This means that whenever Umbraco's.GetPropertyValue<T>is called, the associatedTypeConverterwill be used.
So when Ditto attempts to map the "metaData" DocType property with the POCO's MetaData property - the MetaDataTypeConverter will be called.
Important note: Because Archetype comes with its own custom
ValueConverter, the value type that is passed into ourMetaDataTypeConverterwill be of typeArchetypeModel(as opposed to a JSON string).
From there, our custom converter can use the ArchetypeModel to access its fieldsets and nested property values - see the ConvertFromArchetype method.