KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I need to check equality between two MethodInfos. They are actually the exact same MethodInfo with the exception of the ReflectedType (that is, the DeclaringType is the same and the methods should actually have the same body). There are a number of ways of doing this, but I'm looking for the most efficient. Right now I have: public static bool AreMethodsEqualForDeclaringType(this MethodInfo first, MethodInfo second) { first = first.ReflectedType == first.DeclaringType ? first : first.DeclaringType.GetMethod(first.Name, first.GetParameters().Select(p => p.ParameterType).ToArray()); second = second.ReflectedType == second.DeclaringType ? second : second.DeclaringType.GetMethod(second.Name, second.GetParameters().Select(p => p.ParameterType).ToArray()); return first == second; } This is kind of expensive, so I'm wondering if there's a better way... Should I be comparing the two method bodies instead? eg. first.GetMethodBody() == second.GetMethodBody() Thanks.
Tags (comma-separated)
Save Edits
Cancel