I've wondered how you would go about making a custom generic type, you can use on GetPropertyValue.
I've seen MegaNav use it, lige Model.Content.GetPropertyValue<IEnumerable<MegaNavItem>>("something")
How in the hell did they manage to use MegaNavItem like so?
I was testing it with an extended version of RelatedLinks, and wanted to use it like Model.Content.GetPropertyValue<RelatedLinksCustom>("field") but simply couldn't figure it out.
I ended up writing it something close to this: RelatedLinksCustom(Model.Content.GetPropertyValue("field"))
Custom Generic type
Hi community,
I've wondered how you would go about making a custom generic type, you can use on
GetPropertyValue
.I've seen MegaNav use it, lige
Model.Content.GetPropertyValue<IEnumerable<MegaNavItem>>("something")
How in the hell did they manage to use MegaNavItem like so? I was testing it with an extended version of RelatedLinks, and wanted to use it like
Model.Content.GetPropertyValue<RelatedLinksCustom>("field")
but simply couldn't figure it out.I ended up writing it something close to this:
RelatedLinksCustom(Model.Content.GetPropertyValue("field"))
Hi Tobias
The magic is achieved by creating a PropertyValueConverter
https://our.umbraco.com/documentation/extending/property-editors/value-converters
This tells Umbraco how to convert the stored value into a particular strongly typed object for a property type.
You can see the Meganav example here:
https://github.com/callumbwhyte/meganav/blob/dev/src/Cogworks.Meganav/ValueConverters/MeganavValueConverter.cs
regards
Marc
is working on a reply...