2
var v = xyz.GetType();    
var generic = v.GetMethod("Update", new Type[] { typeof(IEnumerable<>) });//returns null

...

public class Xyz
{
    public void Update<T>(IEnumerable<T> translations) where T : ijk
...

Calling v.GetMethods()[1] returns the correct method.

Draken
  • 3,134
  • 13
  • 34
  • 54
Ante Novokmet
  • 388
  • 3
  • 13
  • 7
    This might be a good place to start - [How do I use reflection to call a generic method?](http://stackoverflow.com/questions/232535/how-do-i-use-reflection-to-call-a-generic-method) – Jason Evans Sep 19 '16 at 14:10
  • I am aware of that, but why doesn't it work in my case? afaik I'm not missing any flags/parameters – Ante Novokmet Sep 19 '16 at 14:45
  • 1
    `IEnumerable<>` is an unbound generic type and is not the same thing as `IEnumerable`. Your call would be the logical way to do it if `GetMethod` supported it, but it doesn't. You'll need something [more complicated](http://stackoverflow.com/questions/4035719/). – Jeroen Mostert Sep 19 '16 at 14:47
  • 1
    The parameter type is `IEnumerable`, not `IEnumerable<>`. There is a difference. – Mr Anderson Sep 19 '16 at 14:47
  • Jeroen's comment is correct. If you want the less-complicated way you can in fact change your method to make it non-generic: `public void Update(IEnumerable translations)` because `IEnumerable` is covariant. – Mr Anderson Sep 19 '16 at 14:51

0 Answers0