I know that it was asked for Reflection on ExpandoObjects here before.
My question is a little different. I have static and dynamic functions which should be executed from some function similar to object ExecuteFunction(string name, params object[] parameters).
I execute the static functions via Reflection. So the question is, if I can reuse the MethodInfo call and get a MethodInfo object from the ExpandoObject? Or do I have to implement 2 functions (One with Action and one with MethodInfo)?
You won’t get any
MethodInfofor the dynamically defined methods on an ExpandoObject.Dynamically defined methods are the same as dynamically defined properties, they just happen to be of a delegate type.
However, this delegate type contains a property named
Methodof typeMethodInfowhich you can utilize:Please note that the first parameter is of type
IDictionary<string, object>.ExpandoObjectimplements this interface, and we need no other features fromExpandoObject, so the parameter is just of the type of the implemented interface we need the functionality of.