Others indicated corrections, but I would like to suggest an alternative IsSubclassOf, and also include public methods:
public IEnumerable<string> GetMethodsOfReturnType(Type cls, Type ret)
{
var methods = cls.GetMethods(BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance);
var retMethods = methods.Where(m => m.ReturnType.IsAssignableFrom(ret))
.Select(m => m.Name);
return retMethods;
}
With IsAssignableFromyou, you don’t need to have an additional “return type exactly the same as the required type”, and it will also work with interfaces.
source
share