I want to use a dynamic object where I’d normally use Dictionary<string, string>.
I want to go from
dict.Add("key", "value");
string val = dict["key"];
to
dyna.key = "value";
string val = dyna.key
Typical ExpandoObject will return an object for dyna.key, what’s an easy way to make it return strings without casting when accessing each value?
EDIT: I’m sorry, I haven’t dug enough into my problem —
It’s not that the code I’m calling can’t use it as a string, it has THIS:
public static implicit operator SomethingSomething(string name)
That’s why it breaks
EDIT2: welp, I’m an idiot, only after recreating it from scratch did I read the full error message: has no applicable method named ‘GetMyClass’ but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
Erm, not exactly, it will return whatever you tell it to return:
of course you can no longer rely on compile time checking and the following code will obviously crash at runtime:
So make sure that you are using the same type as the one used to store the value.
UPDATE:
UPDATE 2:
I still don’t see what the problem is: