public <R> R performActionOnMember(MemberScope<?, ?> member, Function<FieldScope, R> fieldAction,
            Function<MethodScope, R> methodAction) {
        R result;
        if (member instanceof FieldScope) {
            result = fieldAction.apply((FieldScope) member);
        } else if (member instanceof MethodScope) {
            result = methodAction.apply((MethodScope) member);
        } else {
            throw new IllegalStateException("Unsupported member scope of type: " + member.getClass());
        }
        return result;
    }
Helper function to write generic code that targets either a {@link FieldScope} or {@link MethodScope}.

@param <R> type of expected return value
@param member field or method being targeted
@param fieldAction action to perform in case the given member is a {@link FieldScope}
@param methodAction action to perform in case the given member is a {@link MethodScope}
@return value returned by the performed action
@throws IllegalStateException if given member is neither a {@link FieldScope} or {@link MethodScope}
jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeContext.java