如何通过从F#LINQ表达式到C#代码 [英] How to pass LinQ Expressions from F# to C# code

查看:120
本文介绍了如何通过从F#LINQ表达式到C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ReactiveUI有signitures方法,如

 公共静态ReactiveUI.ObservableAsPropertyHelper<&TRET GT; 
ObservableToProperty< TObj,TRET>(
这TObj此,
System.IObservable< TRET>观察到,
System.Linq.Expressions.Expression< System.Func< TObj,TRET> ;>物业,
TRET初值= NULL,
System.Reactive.Concurrency.IScheduler调度= NULL

在F#我怎么样构建

  System.Linq.Expressions对象.Expression< System.Func< TObj,TRET>>财产,

在C#我会做这样的事情。



  this.ObservableAsPropertyHelper(
观察到,
我=> me.MyProperty

修改



我试过





<预类=郎毫升prettyprint-覆盖> m.ObservableToProperty(本,价值,好玩的我 - > me.Property)



<预类=郎毫升prettyprint-覆盖> m.ObservableToProperty(这一点,
值,
新Linq.Expression.Expression(我的乐趣 - > me.Property)

但既不工作。


解决方案

我不知道,如果新的F#3查询表达式帮助你,但旧的PowerPack(仍然伟大工程!)有一个扩展方法 Expr.ToLinqExpression():表达式 ,编译F#报价表达式(即< @我取乐 - > me.MyProperty @> )到LINQ表达式


$ b。 $ b

编辑:
作为丹尼尔指出,的 QuotationToLambdaExpression 做的作品,为F#3。


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

解决方案

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.

这篇关于如何通过从F#LINQ表达式到C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆