
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
762
|
Chapter 13: Reflection
The second method passes in the assembly path, the fully qualified type name, a
method name, and the parameters for this method to find the override that specifi-
cally matches the signature based on the parameters. In this case, the parameter
types of method
Foo are long, double, and byte[]. This method displays the method
that
CSharpRecipes.ReflectionUtils+DerivedOverrides.Foo overrides. The + in the
type name represents a nested class.
Discussion
Determining which methods override their base class methods would be a tedious
chore if it were not for the
GetBaseDefinition method of the System.Reflection.
MethodInfo
type. This method takes no parameters and returns a MethodInfo object
that corresponds to the overridden method in the base class. If this method is used
on a
MethodInfo object representing a method that is not being overridden—as is the
case with a virtual or abstract method—
GetBaseDefinition returns the original
MethodInfo object.
The code for the
FindMethodOverrides methods first loads the assembly using the
asmPath parameter and then gets the type that is specified by the typeName parameter.
Once the type is located, its
Type object’s GetMethod or GetMethods method is called.
GetMethod is used when both the method name and its parameter array are passed ...