Given the following code why is method variable null?
Type[] typeArgs = { typeof(SomeClass) };
var listRef = typeof(List<>);
var list = Activator.CreateInstance(listRef.MakeGenericType(typeArgs));
var method = list.GetType().GetMethod("Add", BindingFlags.Default, null, typeArgs, null);
I have tried many different overloads and BindingFlags but still never get the MethodInfo for List<SomeClass>.Add(SomeClass item)
.
Surely it is something simple I am missing, but any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire