How to fetch data from List<dynamic>()?

My code is like this

var eventDocs = new List<dynamic>();     
foreach (var node in eventtypeNode.GetDescendantNodes())
{
    string files = node.GetProperty("document").Value;
    eventDocs.Add(new { Id = node.Id, Name = node.Name, CreatedOn = node.CreateDate, Path = files });
}

This works good. Now I am trying to fetch the data out of this dynamic list

foreach (var eventDoc in eventDocs)
{
     eventDoc.----  //nothing comes on intellisence
}

Nothing comes on IntelliSense? Am I doing anything wrong?

Jon Skeet
people
quotationmark

You won't get anything from Intellisense precisely because you've got a List<dynamic>. You're saying, "I don't know at compile-time what this list will contain. When I access members of the elements, just bind that dynamically at execution-time."

Given that you're deferring binding to execution time, why would you be surprised that Intellisense can't tell what will be in the list?

It looks to me like you should change your code to use a LINQ query to start with - then you can have a list with a known element type, which will be an anonymous type.

var eventDocs = eventtypeNode.GetDescendantsNodes()
      .Select(node => new { Id = node.Id, 
                            Name = node.Name, 
                            CreatedOn = node.CreateDate,
                            Path = node.GetProperty("document").Value })
      .ToList();

people

See more on this question at Stackoverflow