Hi guys,
I'm trying to get a method an invoke it, ignoring the case of the name passed in. The following works 100% fine:
Ok, and then we make the following call:
The above works fine. But the call is case-sensitive with respect to the procName, which is "MyMethod" in this case. Often it's hard to know up front if a method is named, say, "SubString" or "Substring" and here it would matter. A lot.
As a VB programmer this case sensitivity is more than a little annoying. So I then attempted the following, which makes use of binding flags, in particular the 'System.Reflection.BindingFlags.IgnoreCase' binding flag:
The above works perfectly too... However, it does *NOT* ignore case! This would seem to be the point of 'BindingFlags.IgnoreCase', right??
Now this might not be a brilliant thing for me to be doing, for I assume that a C# assembly could have two methods with the same name only differing by case. (Although, they should not both be public in this situation, but theoretically could be.) I really wonder how VB would deal with calling into a C# assembly in this situation with early-bound calls, never mind late bound.
But for the moment, I'm willing to assume that the call to the Method is safe as a case-insensitive call. So any ideas on how I can get 'System.Reflection.BindingFlags.IgnoreCase' to work?
Thanks all in advance...
Mike
I'm trying to get a method an invoke it, ignoring the case of the name passed in. The following works 100% fine:
Visual Basic:
Dim procName As String
procName = "MyMethod" '<-- Or whatever is to be called.
Dim paramTypes As Type()
' I then set the paramTypes for the arguments properly...
Visual Basic:
Dim methInfo As Reflection.MethodInfo = _
objectReference.GetType.GetMethod(procName, paramTypes)
As a VB programmer this case sensitivity is more than a little annoying. So I then attempted the following, which makes use of binding flags, in particular the 'System.Reflection.BindingFlags.IgnoreCase' binding flag:
Visual Basic:
Dim methInfo As Reflection.MethodInfo = _
objectReference.GetType.GetMethod( _
procName, _
System.Reflection.BindingFlags.IgnoreCase Or _
System.Reflection.BindingFlags.Public Or _
System.Reflection.BindingFlags.Instance, _
Type.DefaultBinder, _
paramTypes, _
Nothing)
Now this might not be a brilliant thing for me to be doing, for I assume that a C# assembly could have two methods with the same name only differing by case. (Although, they should not both be public in this situation, but theoretically could be.) I really wonder how VB would deal with calling into a C# assembly in this situation with early-bound calls, never mind late bound.
But for the moment, I'm willing to assume that the call to the Method is safe as a case-insensitive call. So any ideas on how I can get 'System.Reflection.BindingFlags.IgnoreCase' to work?
Thanks all in advance...
Mike