How to pass LinQ expressions from F # code to C #

ReactiveUI has methods with signs like

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 ) 

In F #, how would I build an object like

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

In C #, I would do something like

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

EDIT

I tried

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

and

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

but does not work

+6
source share
1 answer

I'm not sure if the new F # 3 query requests help you, but the old PowerPack (which still works great!) Has an extension method Expr.ToLinqExpression() : Expression to compile F # quote expressions (i.e. <@ fun me -> me.MyProperty @> ) in a LINQ expression.

Edit: As Daniel pointed out, QuotationToLambdaExpression does the work for F # 3.

+4
source

All Articles