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?
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");
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.
Intellisense for DynamicNodeList dynamic members?
In my Razor macro, the following results in an error:
However, if I make node `dynamic` everything works:
This is constantly frustrating me because:
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):
Got the same problem with Umbraco.Content(1804).Children.Where("Visible")
The Children and Where are just good luck.
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"
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.
is working on a reply...