Quantcast
Channel: Answers by "hoekkii"
Viewing all articles
Browse latest Browse all 26

Answer by hoekkii

$
0
0
Reflection does not care about function overloading. Instead use `Type::GetMethods : MethodInfo[]` instead and make a function like this: public static void SafeInvoke(this MethodInfo[] methods, object target, params object[] args) { foreach (var method in methods) { var parameters = method.GetParameters(); if (args.Length != parameters.Length) continue; // Check if a type does not match if (parameters.Where((t, i) => args[i].GetType() != t.ParameterType).Any()) continue; method.Invoke(target, args); return; } throw new ArgumentException(); } Note: This is not tested Edit: Alternatively you get use `Type::GetMethod("MyMethodName", new [] {typeof(MyType),})`

Viewing all articles
Browse latest Browse all 26

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>