Detecting overriding with reflection?

  • Thread starter Thread starter Joannes Vermorel [MVS]
  • Start date Start date
J

Joannes Vermorel [MVS]

Given a System.Type, I would like to detect whether the method
object.GetHashCode() has been overriden or not ? How can I achieve that with
reflexion? I have read the MethodBase documentation, but I do not see any
solution for now.

Thanks in advance,
Joannès
http://www.vermorel.com
 
Joannes,
Given a System.Type, I would like to detect whether the method
object.GetHashCode() has been overriden or not ? How can I achieve that with
reflexion?

if ( t.GetMethod("GetHashCode", BindingFlags.Public |
BindingFlags.Instance | BindingFlags.DeclaredOnly) != null )



Mattias
 
Given a System.Type, I would like to detect whether the method
if ( t.GetMethod("GetHashCode", BindingFlags.Public |
BindingFlags.Instance | BindingFlags.DeclaredOnly) != null )

Thanks, I had missed the BindingFlags.DeclaredOnly flag. That's what I was
needing.
Actually the solution might be a bit more complicated. Because, we can have

class A
{
public override int GetHashCode() { foo }
}

class B : A
{
}

The class B has no declared method "GetHashCode", nevertheless the behavior
of B.GetHashCode() is overriden.

Joannès
 
Back
Top