0

I am using below method to create the expression for searching a string in an entity

MethodInfo methodInfo = typeof(string).GetMethod("Contains", new[] { typeof(string) });

this works fine in the case of string. But when I tried with the Dictionary object as

MethodInfo methodInfo = typeof(Dictionary<string, string>).GetMethod("Any", new[] { typeof(Func<string,string>),typeof(bool)});

but it returns null value always. Anybody let me know how to use the method to get correct value of the MethodInfo

1 Answers1

2

Any is not a method of Dictionary<K, V>. It is an extension method belonging to Enumerable. Therefore you can't find it on Dictionary<K, V>.

See How do I invoke an extension method using reflection? how it should be done.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325