Copied to clipboard

Flag this post as spam?

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


  • Tobias M. Madsen 12 posts 102 karma points
    Aug 26, 2019 @ 20:46
    Tobias M. Madsen
    0

    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"))

  • Marc Goodson 1451 posts 9716 karma points MVP 5x c-trib
    Aug 27, 2019 @ 23:26
    Marc Goodson
    100

    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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies