/// <summary> /// Returns all items with a mapper returning an item deriving from <typeparamref name="T" /> /// </summary> /// <typeparam name="T">The base type to look for</typeparam> /// <returns>A list of items that derives from <typeparamref name="T" /></returns> public IEnumerable <T> InvokeDerivedMappers <T>() { return(Flat .Where(n => n.Matched) .Where(n => n != this) .Where( n => n.Token.GetType().IsConstructedGenericType && n.Token.GetType().GetGenericTypeDefinition() == typeof(BNF.Mapper <>) && typeof(T).IsAssignableFrom(n.Token.GetType().GetGenericArguments().First()) ) .Select( n => { try { return (T)n.Token .GetType() .GetMethod(nameof(BNF.Mapper <T> .InvokeMatcher)) .Invoke(n.Token, new object[] { n }); } catch (System.Reflection.TargetInvocationException tex) { // As we use reflection, unwrap the exception here throw tex.InnerException; } } )); }