In C#
你有:
.Return(n => n.As<Project>())
如果我们把它拿出来看看类型,n => n.As<Project>()
is:
Expression<Func<ICypherResultItem, Project>>
要创建它,请使用Expression Trees
in C#
,我们最终会做这样的事情:
ParameterExpression parameter = Expression.Parameter(typeof (ICypherResultItem), "n");
MethodCallExpression right = Expression.Call(parameter, typeof (ICypherResultItem).GetMethod("As").MakeGenericMethod(typeof(Project)));
Expression<Func<ICypherResultItem, Project>> expression = Expression.Lambda<Func<ICypherResultItem, Project>>(right, parameter);
因此,将其转换为 PowerShellI think是这样的:
$exp = [System.Linq.Expressions.Expression]
$param = $exp::Parameter([Neo4jClient.Cypher.ICypherResultItem], "n")
$body = $exp::Call($param, [Neo4jClient.Cypher.ICypherResultItem].GetMethod("As").MakeGenericMethod[Project])
$lambda = $exp::Lambda([Func[ICypherResultItem, Project]], $body, $param)
I am in no way一个 powershell 人,我怀疑你能够翻译C#
更好,但希望这能让你走上正确的轨道......
*更新我*一个小修复就可以让一切正常工作。声明一个 var 来保存类型数组MakeGenericMethod
期望,并将其传递给:
$PrjType = @((new-object Project).GetType())
$body = $exp::Call($param, [Neo4jClient.Cypher.ICypherResultItem].GetMethod("As").MakeGenericMethod($PrjType))