简体   繁体   English

如何将Linq表达式从F#传递给C#代码

[英]How to pass LinQ Expressions from F# to C# code

ReactiveUI has methods with signitures like 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
  )

In F# How would I construct an object like 在F#中我如何构造一个像这样的对象

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

In C# I would do something like 在C#中,我会做类似的事情

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 但都没有工作

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 (ie <@ fun me -> me.MyProperty @> ) into LINQ expressions. 我不确定新的F#3查询表达式是否对您有所帮助,但是旧的PowerPack(仍然很好用!)有一个扩展方法Expr.ToLinqExpression() : Expression ,用于编译F#引用表达式(即<@ fun me -> me.MyProperty @> )进入LINQ表达式。

Edit: As Daniel had pointed out, QuotationToLambdaExpression does the works, for F# 3. 编辑:正如丹尼尔指出的那样, QuotationToLambdaExpression为F#3做了工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM