var leftCurrent = leftArray.GetValue(i);
var rightCurrent = rightArray.GetValue(i);
var mi = typeof (PropertyCompare).GetMethod("NotEqualProperties");
mi.MakeGenericMethod(leftCurrent.GetType());
var notEqualProps = mi.Invoke(null,new []{leftCurrent, rightCurrent});
if(notEqualProps != null)
result.Add(new ArraysDiffResult(i, notEqualProps as List<string>));
Why does this code throws InvalidOperationException ( Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.) ?
NotEqualProperties is static generic method..
UPD : I’ve already found solution. Just forgot to assign new MethodInfo…(Epic Fail..)
But how about performance?
MakeGenericMethodreturns a newMethodInfoinstance. (MethodInfois immutable)Your code creates this new instance, throws it away, then continues using the open (non-parameterized)
MethodInfo.You need to use the new instance, like this:
Yes; reflection is much slower than normal method calls.
However, unless you’re calling it in a tight loop, it’s not necessarily an issue.