Copied to clipboard

Flag this post as spam?

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


  • Robin Winslow Morris 20 posts 82 karma points
    Dec 04, 2012 @ 15:39
    Robin Winslow Morris
    0

    Intellisense for DynamicNodeList dynamic members?

    In my Razor macro, the following results in an error:

    using umbraco.MacroEngines
    var node = new DynamicNode(Model.Id);
    var children = node.Children;
    // 'DynamicNode' does not contain a definition for 'Children'
    var descendants = node.Descendants().Where("Visible");
    // The type arguments for 'DynamicNodeList.Where<T>(string, params object[])' cannot be inferred from the usage.

    However, if I make node `dynamic` everything works:

    using umbraco.MacroEngines
    dynamic node = new DynamicNode(Model.Id);
    dynamic descendants = node.Descendants(); // Note the "dynamic"
    descendants = descendants.Where("Visible");
    

    This is constantly frustrating me because:

    • I often have an object which I know is of type "DynamicNode" or "DynamicNodeList" but I have no idea if it's been dynamically declared or not and so how I'm allowed to use it
    • I can't use intellisense to discover properties, I have to just know they're there
    Does anyone have any idea how to get intellisense to know about these properties? Or even better if I can get a non-dynamic instantiation of these types to have these properties?

  • Robin Winslow Morris 20 posts 82 karma points
    Dec 04, 2012 @ 15:42
    Robin Winslow Morris
    0

    I can't edit my post above - I get the error in my browser: "Error parsing XSLT file: \xslt\forum-commentsList.xslt".

    In my original post that second block of code should look like this (although the above one also works):

    using umbraco.MacroEngines
    dynamic node = new DynamicNode(Model.Id);
    var children = node.Children;
    var descendants = node.Descendants().Where("Visible");
  • Edwin van Koppen 156 posts 270 karma points
    Dec 04, 2012 @ 16:17
    Edwin van Koppen
    0

    Got the same problem with Umbraco.Content(1804).Children.Where("Visible")

    The Children and Where are just good luck.

     

  • John Ligtenberg 53 posts 214 karma points
    Feb 12, 2013 @ 10:43
    John Ligtenberg
    0

    This seems to be answered here:

    http://umbraco.com/follow-us/blog-archive/2011/2/24/umbraco-47-razor-feature-walkthrough-%E2%80%93-part-2.aspx

    "When you define variables like this, you must declare them with the type dynamic:
    e.g.

    dynamic node = new DynamicNode(1046)


    if you don't do this, Razor won't be able to find properties or methods on the new type"

  • Robin Winslow Morris 20 posts 82 karma points
    Feb 15, 2013 @ 01:01
    Robin Winslow Morris
    0

    Isn't that exactly what I said? If you use "dynamic" everything works. But this sucks, because you don't get any intellisense - you have to either know or guess what properties and methods are available. It sucks.

Please Sign in or register to post replies

Write your reply to:

Draft