1

カスタム式を構築するために、リフレクションを使用して正しい「Where」拡張メソッドを返そうとしています。私はいくつかの方法を試しましたが、最も近いものは例外をスローします:

これは、Enumrable クラスで 2 つの Where メソッドが定義されているためだとわかっていますが、述語だけを使用する Where メソッドを返すにはどうすればよいですか?

 Func<T, bool>. 

私が現時点で持っているものは次のとおりです。

var collectionType = typeof(TSub);
Type tIEnumerable = typeof(IEnumerable<>).MakeGenericType(collectionType);

MethodInfo methodInfo =
        typeof(Enumerable)
        .GetMethod("Where")                
        .MakeGenericMethod(collectionType);

私も試しました(これはnullを返します):

MethodInfo methodWhere = typeof(Enumerable).GetMethod("Where", new[] { typeof(TSub )});

および (null も返す)

 MethodInfo methodWhere = typeof(Enumerable).GetMethod("Where", new[] { collectionType })

そして(これは同じあいまいな例外を返します)

MethodInfo methodWhere = typeof(Enumerable).GetMethod("Where", BindingFlags.Public |      BindingFlags.Static)

誰でも助けてもらえますか?

ありがとう

4

4 に答える 4