Skip to content

Linq queries against Dynamic? #3

@drosenba

Description

@drosenba

Is it possible to query using Linq?
When I first tried
dynamic dynamicYaml = new DynamicYaml(MappingYaml);
var x = (decimal)dynamicYaml.items.First().price;
it complained that First() was not a method of DynamicYaml. So I added it, and it worked:
public DynamicYaml First()
{
return Children.First();
}

Then I added
public DynamicYaml First(Func<DynamicYaml,bool> predicate)
{
if (predicate == null) throw new ArgumentNullException("predicate");
return Children.First(predicate);
}

But if I try
var x = (decimal)dynamicYaml.items.First(x => ((string)x.receipt).Contains("OZ")).price;
the compiler complains :
"Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions