Tip: how to tell a regular method apart from property getter/setters and event add/remove

Rather than typical code like:

private static MethodInfo GetFirstMethodWithReturnType(Type type)
{
    return
        type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
            .Where(method => !method.Name.StartsWith("get_") && !method.Name.StartsWith("set_") && 
!method.Name.StartsWith("add_") && !method.Name.StartsWith("remove_")) .FirstOrDefault(method => (method.ReturnType != typeof(void))); } ...

Read full article

No Comments