I've seen use of a method called AsDynamic(). IIRC it was an extension method. The idea is that for any object you can call myObject.AsDynamic() and get a dynamic version of it.
Thing is, I just can't find the AsDynamic() method, despite much Googling. I'm assuming it's something actually have implemented themselves, and I'd like to do the same.
I'm using .NET 4 client profile, and am very confused. :)
Many thanks in advance.
Turns out I was right - it was something someone (Greg Young) had a specific implementation for. The details of the implementation were taken from David Ebbo's blog:
Use C# 4.0 dynamic to drastically simplify your private reflection code
You can just assign the variable in a dynamic var
Foo foo = GetFooFromSommehere();
dynamic dyn = foo;
Or cast it:
Foo foo = GetFooFromSommehere();
var dyn = (dynamic) foo;
Why should there be AsDynamic() method?
The ToList() method actually does stuff instead of casting unlike with dynamic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With