Consider these options:
class A { public virtual void Doit() { } } class B : A { public new virtual void Doit() { } }
or
class B : A { public override virtual void Doit() { } }
I cannot find the difference in the return results of typeof(B).GetMethod("Doit");
In both cases, MethodInfo.DecalringType is class B, and the other properties seem the same. Am I missing something or is there no way to distinguish them?
Update:
When I ran the sample in LINQPAd, I noticed a slight difference in the Attributes property:
for new virtual value was - PrivateScope, Public, Virtual, HideBySig, VtableLayoutMask
for override - PrivateScope, Public, Virtual, HideBySig
Update 2:
I googled near VtableLayoutMask and went back to https://stackoverflow.com/a/312947/
Udate 3:
final code:
public static class MethodInfoExtensions { public static bool IsOverriden(this MethodInfo method) { Contract.Requires<ArgumentNullException>(method != null, "method"); return method.IsVirtual && !method.IsStatic
Pavel voronin
source share