Hello,

Reflection seems to be pretty inconsistent with MethodInfos. In some cases
derived classes have their own MethodInfo objects for inherited (non-
overridden) methods, in some cases they get the same object as the base
class.

example:

class Base {
 protected void Method1(ref int i) { }
}

class Derived: Base {
}

Main {
 MethodInfo m1 = typeof(Derived).GetMethod ("Method1",
   BindingFlags.NonPublic|BindingFlags.Instance);
 MethodInfo m2 = typeof(MarshalByRefObject).GetMethod
      ("MemberwiseClone",
   BindingFlags.NonPublic|BindingFlags.Instance);
}

in this case, the following expressions are true:

m1 == m1.GetBaseDefinition()
m2 != m1.GetBaseDefinition()

m1.GetBaseDefinition.ReflectedType == Base // where it is declared
m2.GetBaseDefinition.ReflectedType == MarshalByRefObject // where it was
retreived


A new MethodInfo is created for MarshalByRefObject.MemberwiseClone,
although MarshalByRefObject doesn't override or redefine it.
No new MethodInfo is created for Derived.Method1.

I also cannot see any differences in the IL code of the methods, except
that MemberwiseClone is "internal".


What's the difference? Am I missing something or is Reflection just being
dumb in this case?

Thanks,
Stefan

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to