从表达式中提取 lambda?
我想实现这个功能:
Public Function GetFunc(Of TSource, TResult) _
selector As Expression(Of Func(Of TSource, TResult)) _
As Func(Of TSource, TResult)
'Implement here
End Function
更新
我有以下问题,它是函数的一部分:
Dim obj As Object = value
For Each exp In expressions
If obj Is Nothing Then Return [default]
Select Case exp.NodeType
Case ExpressionType.Call
Dim method = DirectCast(exp, MethodCallExpression)
Dim info = method.Method
If method.Object Is Nothing Then
Dim args = {obj}.Union(method.Arguments.Skip(1))
'The following line throws the exception, see details bellow
obj = info.Invoke(Nothing, args.ToArray)
Else
obj = info.Invoke(obj, method.Arguments.ToArray)
End If
异常详细信息:
ArgumentException:
Object of type 'System.Linq.Expressions.Expression`1
[System.Func`3[System.Char,System.Char,System.Char]]'
cannot be converted to type
'System.Func`3[System.Char,System.Char,System.Char]'.
I want to implement this function:
Public Function GetFunc(Of TSource, TResult) _
selector As Expression(Of Func(Of TSource, TResult)) _
As Func(Of TSource, TResult)
'Implement here
End Function
UPDATE
I have the following issue, it's a part of a function:
Dim obj As Object = value
For Each exp In expressions
If obj Is Nothing Then Return [default]
Select Case exp.NodeType
Case ExpressionType.Call
Dim method = DirectCast(exp, MethodCallExpression)
Dim info = method.Method
If method.Object Is Nothing Then
Dim args = {obj}.Union(method.Arguments.Skip(1))
'The following line throws the exception, see details bellow
obj = info.Invoke(Nothing, args.ToArray)
Else
obj = info.Invoke(obj, method.Arguments.ToArray)
End If
Exception Details:
ArgumentException:
Object of type 'System.Linq.Expressions.Expression`1
[System.Func`3[System.Char,System.Char,System.Char]]'
cannot be converted to type
'System.Func`3[System.Char,System.Char,System.Char]'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)