asp.net - C# - How to use Reflection to invoke static method with variable number of parameters -
i want identify next method via reflection:
string.concat(params string[] args); this have tried:
methodinfo concatmethod = typeof(string).getmethod("concat", new type[] { typeof(string[]) }); the method beingness identified correctly, when seek invoke it:
object concatresult = concatmethod.invoke(null, new object[] { "a", "b" }); i next exception:
targetparametercountexception: parameter count mismatch. also note passing null instance argument invoke method, because method static , hence instance not needed. approach correct?
ps: want simulate next call:
string.concat("a", "b");
each element of input array parameter method. overload of concat have takes single string[] argument need:
object concatresult = concatmethod.invoke(null, new object[] { new string[] { "a", "b" } }); c# asp.net exception reflection
No comments:
Post a Comment