mercredi 29 avril 2015

Does calling a method on a dynamic object basically do GetMethod().Invoke()?

The title is basically my question. Under the covers does the last line of this:

Type xmlCodecType = typeof(XmlCodec<>).MakeGenericType(typeof(SomeObjectProperty));
dynamic xmlCodec = Activator.CreateInstance(xmlCodecType);
xmlCodec.ReadCollection(xmlCodec.GetCollectionName());

basically do this:

MethodInfo method1 = xmlCodec.GetType().GetMethod("ReadCollection");
MethodInfo method2 = xmlCodec.GetType().GetMethod("GetCollectionName");
method1.Invoke(xmlCodec, new obj[] { method2.Invoke(xmlCodec, null) });

when executed??

Most of what I have written is using the reflection method because it is what I was used to and just feels a bit more 'catch errors during compile time' with the passing of the write types and objects and such. Dynamic is a bit more hands off. However reflection can be harder to read/follow at times whereas while dynamic is not always a keyword in a language, it is common concept across most of them.





Aucun commentaire:

Enregistrer un commentaire