私はこのクエリを持っています:
Dim test = result.GroupBy(Function(row) groupedindexes.Select(
Function(grpindex) row(grpindex)).ToArray, comp)
式ツリーを作成しています。関数内のパーツを既にビルドしており、メソッドGroupBy
を呼び出したいと思います。ToArray
コードは次のとおりです。
Public Function Grouping(ByVal result As IEnumerable(Of Object()), ByVal groupedindexes As List(Of Integer), ByVal comparer As compare) As Expression
Dim groupbyMethod = GetType(Enumerable).GetMethods(BindingFlags.Public Or BindingFlags.Static).First(Function(m) m.Name = "GroupBy").MakeGenericMethod(GetType(Object()), GetType(System.Collections.Generic.IEqualityComparer(Of Object())))
Dim convertMethod As MethodInfo = Nothing
Dim rowParameter = Expression.Parameter(GetType(Object()), "Row")
Dim indexParameter = Expression.Parameter(GetType(Integer), "grpindex")
Dim methodstring As String
Dim expr As Expression = Nothing
Dim index As Integer
Dim grpindexes As Expression = Expression.Constant(groupedindexes, GetType(System.Collections.Generic.List(Of Integer)))
Dim selectMethod = GetType(Enumerable).GetMethods(BindingFlags.Public Or BindingFlags.Static).First(Function(m) m.Name = "Select").MakeGenericMethod(GetType(Integer), GetType(Object))
Dim toarrayMethod2 = GetType(Enumerable).GetMethods(BindingFlags.Public Or BindingFlags.Static).First(Function(m) m.Name = "ToArray").MakeGenericMethod(GetType(Object))
Dim cmp As Expression = Expression.Constant(comparer, GetType(compare))
Dim fieldselector As Expressions.LambdaExpression
fieldselector = Expression.Lambda(Expression.ArrayAccess(rowParameter, indexParameter), indexParameter)
Dim outerfieldselector As Expressions.LambdaExpression
outerfieldselector = Expression.Lambda(Expression.Call(selectMethod, grpindexes, fieldselector), rowParameter)
expr = Expression.Call(groupbyMethod, Expression.Call(outerfieldselector, toarrayMethod2), cmp)
Return expr
End Function
次の行にエラー メッセージが表示されますexpr = ...
。静的メソッドには null インスタンスが必要です。非静的メソッドには非 null インスタンスが必要です。
このエラー メッセージは既に知っていますが、式の呼び出しは正しいと思います: I call the ToArray
method on outerfieldselector
.
手伝ってくれませんか?コードをコピーして貼り付けてテストできます。必要に応じて、比較クラスを削除できます。
ありがとう。