7

ReactiveUI 具有带有签名的方法,例如

public static ReactiveUI.ObservableAsPropertyHelper<TRet> 
  ObservableToProperty<TObj, TRet>(
    this TObj This, 
    System.IObservable<TRet> observable, 
    System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, 
    TRet initialValue = null, 
    System.Reactive.Concurrency.IScheduler scheduler = null
  )

在 F# 中,我将如何构造一个像

System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, 

在 C# 中,我会做类似的事情

this.ObservableAsPropertyHelper(
    observable,
    me => me.MyProperty
)

编辑

我试过了

m.ObservableToProperty(this, value, fun me -> me.Property )

m.ObservableToProperty(this, 
            value, 
            new Linq.Expression.Expression(fun me -> me.Property )

但两者都不起作用

4

1 回答 1

5

我不确定新的 F# 3 查询表达式是否对您有帮助,但旧的 PowerPack(仍然很好用!)有一个扩展方法Expr.ToLinqExpression() : Expression,可以将 F# 引用表达式(即<@ fun me -> me.MyProperty @>)编译成 LINQ 表达式。

编辑: 正如 Daniel 指出的那样,QuotationToLambdaExpression为 F# 3 完成了工作。

于 2012-12-14T08:26:44.697 回答