The problem is not the code, the problem is that you apparently can't evaluate dynamic objects from the immediate window.
I'm trying to tack on methods to an ExpandoObject but not sure how to get it to work. Here's my code:
dynamic myObj = new ExpandoObject();
myObj.First = "Micah";
myObj.Last = "Martin";
myObj.AsString = new Func<string>(() => myObj.First + " " + myObj.Last);
//No matter what I do I get 'object' does not contain a definition for 'AsString'
myObj.AsString;
myObj.AsString();
myObj.AsString.Invoke();
Anyone know how to do this?
Are you sure you included all the code?
I just tested and ran the following and was successful:
dynamic obj = new ExpandoObject();
obj.First = "Hello";
obj.Last = "World!";
obj.AsString = new Func<string>(() => obj.First + " " + obj.Last);
// Displays "Hello World!"
Console.WriteLine(obj.AsString());
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