Reflecting over classes in .NET produces methods only differing by a modifier
- by mrjoltcola
I'm a bit boggled by something, I hope the CLR gearheads can help. Apparently my gears aren't big enough.
I have a reflector utility that generates assembly stubs for Cola for .NET, and I find classes have methods that only differ by a modifier, such as virtual. Example below, from Oracle.DataAccess.dll, method GetType():
class OracleTypeException : System.SystemException {
virtual string ToString ();
virtual System.Exception GetBaseException ();
virtual void set_Source (string value);
virtual void GetObjectData (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
virtual System.Type GetType (); // here
virtual bool Equals (object obj);
virtual int32 GetHashCode ();
System.Type GetType (); // and here
}
What is this?
I have not been able to reproduce this with C# and it causes trouble for Cola as it thinks GetType() is a redefinition, since the signature is identical.
My method reflector starts like this:
static void DisplayMethod(MethodInfo m)
{
if (
// Filter out things Cola cannot yet import, like generics, pointers, etc.
m.IsGenericMethodDefinition ||
m.ContainsGenericParameters ||
m.ReturnType.IsGenericType ||
!m.ReturnType.IsPublic ||
m.ReturnType.IsArray || m.ReturnType.IsPointer || m.ReturnType.IsByRef || m.ReturnType.IsPointer
|| m.ReturnType.IsMarshalByRef
|| m.ReturnType.IsImport
)
return;
// generate stub signature
// [snipped]
}