如何将Linq表达式从F#传递给C#代码
ReactiveUI的方法有像
public static ReactiveUI.ObservableAsPropertyHelper ObservableToProperty( this TObj This, System.IObservable observable, System.Linq.Expressions.Expression<System.Func> property, TRet initialValue = null, System.Reactive.Concurrency.IScheduler scheduler = null )
在F#中我如何构造一个像这样的对象
System.Linq.Expressions.Expression<System.Func> 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 )
但都没有工作
我不确定新的F#3查询表达式是否对您有所帮助,但是旧的PowerPack(仍然很好用!)有一个扩展方法Expr.ToLinqExpression() : Expression
,用于编译F#引用表达式(即<@ fun me -> me.MyProperty @>
)进入LINQ表达式。
编辑:正如丹尼尔指出的那样, QuotationToLambdaExpression为F#3做了工作。