Copied to clipboard

Flag this post as spam?

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


  • Jeroen Wijdeven 31 posts 72 karma points MVP
    Dec 04, 2013 @ 22:41
    Jeroen Wijdeven
    0

    How to get the Type of a macro parameter in a MacroPartial

    I need to get the type of a macro parameter. To do so I neeed to get / create a MacroModel. Below the code I'am using for this:

    var macro = umbraco.cms.businesslogic.macro.Macro.GetById(Model.MacroId);
    var model = new umbraco.cms.businesslogic.macro.MacroModel(macro);
    
    //for example: model.Properties.First().Type
    
    //and map the values to the collection aswell
    var source = Model.MacroParameters.Join(model.Properties,
      mod => mod.Key, mm => mm.Key,
      (mod, mm) => new umbraco.cms.businesslogic.macro.MacroPropertyModel(mod.Key, mod.Value.ToString(), mm.Type, mm.CLRType));
    

    This doesn't feel right, especially because the "PartialViewMacroController" returns a "PartialViewMacroModel" instead of the "MacroModel".

    See the source of the PartialViewMacroController https://github.com/umbraco/Umbraco-CMS/blob/565a020acf1363413d3f75a5e8588dc1dfc90cad/src/Umbraco.Web/Macros/PartialViewMacroController.cs

    some background

    So, why do I need the Type? I need this because I like to create value converters for the parameters for which the implementation can be used in all macropartials. For example when the type is "contentPicker" I like to return a IPublishedContent..

    //something like, or something similar
    public string Convert(MacroPropertyModel value)
    

    the real question

    Is there another way to get the type? Or maybe there is a way to create value converters for MacroParameters?

Please Sign in or register to post replies

Write your reply to:

Draft