7

ReactiveUI has methods with signitures 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 construct 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've tried

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

and

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

but neither work

ildjarn
  • 62,044
  • 9
  • 127
  • 211
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217

1 Answers1

5

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

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

Ramon Snir
  • 7,520
  • 3
  • 43
  • 61
  • Tried that but I got a result of type "LinqExpression" instead of "LinqExpression>" – bradgonesurfing Dec 14 '12 at 09:09
  • @bradgonesurfing http://msdn.microsoft.com/en-us/library/bb335710.aspx, specifically `Use the Lambda(Expression, IEnumerable) or Lambda(Expression, ParameterExpression[]) method to create an Expression object.` . – Ramon Snir Dec 14 '12 at 10:04
  • 8
    It looks like [`QuotationToLambdaExpression`](http://msdn.microsoft.com/en-us/library/hh324072.aspx) is the way to do it in F# 3.0. – Daniel Dec 14 '12 at 15:16