How to add T to the list <T>, where List <T> masquerades as "dynamic", and T as "object"?
How can I change this fragment to correctly add an instance of A to List<A> , B to List<B> , etc.?
// someChild actual type is A object someChild = GetObject(); // collection actual type is List<A> though method below returns object dynamic list = GetListFromSomewhere(...); // code below throws a RuntimeBinderException list.Add(somechild); The exception is thrown because while Add() detected by the binder, it goes into dynamic , which does not have overload permission. I prefer not to modify the above to use reflection, or at least to minimize this. I have access to an instance of System.Type for each of A and List<A> . A class or method containing the above code is not in itself general.
All you need to do is bind to the dynamic argument, so you just need someChild type for dynamic :
dynamic someChild = GetObject(); dynamic list = GetListFromSomewhere(...); list.Add(somechild); In your previous code, the compiler would remember that the someChild time type someChild was object and therefore this compilation time type was used instead of the runtime type. Runtime binding is intelligent only for dynamically expressing dynamic expressions dynamically to resolve overload.