LINQ的;表达式解析器? [英] Linq; expression parser?

查看:74
本文介绍了LINQ的;表达式解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linq中,你显然可以获得一个有意义的身体和

表达式'.ToString();随机问题 - 有没有人知道linq

还包括一个解析器?它似乎可能是一个方便的方式



IBindingListView.Filter写一个安全但简单的实现(即没有编码)(通过编译为Predicate< T> ;)。


有人知道这是否可行吗?


Marc

In Linq, you can apparently get a meaningful body from and
expression''s .ToString(); random question - does anybody know if linq
also includes a parser? It just seemed it might be a handy way to
write a safe but easy implementation (i.e. no codedom) for an
IBindingListView.Filter (by compiling to a Predicate<T>).

Anybody know if this is possible at all?

Marc

推荐答案

Marc Gravell写道:
Marc Gravell wrote:

在Linq中,你显然可以获得一个有意义的身体和

expression'的.ToString();随机问题 - 有没有人知道linq

还包括一个解析器?它似乎可能是一个方便的方式



IBindingListView.Filter写一个安全但简单的实现(即没有编码)(通过编译为Predicate< T> ;)。


有人知道这是否可行?
In Linq, you can apparently get a meaningful body from and
expression''s .ToString(); random question - does anybody know if linq
also includes a parser? It just seemed it might be a handy way to
write a safe but easy implementation (i.e. no codedom) for an
IBindingListView.Filter (by compiling to a Predicate<T>).

Anybody know if this is possible at all?



为什么要在字符串输出上使用解析器?因为那个解析器

会生成一个解析树,它看起来非常类似于你在上面调用ToString()的

表达式树。


所以解释表达式树。


FB


-

----- -------------------------------------------------- -----------------

LLBLGen Pro的首席开发人员,.NET的高效O / R映射器

LLBLGen Pro网站: http://www.llblgen.com

我的.NET博客: http://weblogs.asp.net/fbouma
Microsoft MVP(C#)

-------------------------------- ----------------------------------------

Why would you use a parser on the string output? Because that parser
will produce a parse tree which will look very similar to the
expression tree you called ToString() on :)

So interpret the expression tree instead.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------


Frans Bouma [C#MVP]< pe ****************** @ xs4all.nlwrote:
Frans Bouma [C# MVP] <pe******************@xs4all.nlwrote:

Marc Gravell写道:
Marc Gravell wrote:

In Lin q,你显然可以得到一个有意义的身体和

表达式'.ToString();随机问题 - 有没有人知道linq

还包括一个解析器?它似乎可能是一个方便的方式



IBindingListView.Filter写一个安全但简单的实现(即没有编码)(通过编译为Predicate< T> ;)。


有人知道这是否可行?
In Linq, you can apparently get a meaningful body from and
expression''s .ToString(); random question - does anybody know if linq
also includes a parser? It just seemed it might be a handy way to
write a safe but easy implementation (i.e. no codedom) for an
IBindingListView.Filter (by compiling to a Predicate<T>).

Anybody know if this is possible at all?



为什么要在字符串输出上使用解析器?因为那个解析器

会生成一个解析树,它看起来非常类似于你在上面调用ToString()的

表达式树。


因此,请解释表达式树。


Why would you use a parser on the string output? Because that parser
will produce a parse tree which will look very similar to the
expression tree you called ToString() on :)

So interpret the expression tree instead.



我认为重点是解析从ToString创建*没有*

的表达式树,但是从我理解了

Marc'的介绍性句子实际上意味着:有一个有用的

格式的LINQ表达式,如ToString方法所示 ;


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复该群组,请不要给我发邮件

I think the point would be to parse expression trees which *hadn''t*
been created from ToString, but read in from a file etc. I understood
Marc''s introductory sentence to effectively mean: "there''s a useful
format for LINQ expressions, as shown by the ToString method".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Jon正确地解释了我的烦恼...我的观点是,与原始的.Net 2.0谓词不同,它是b $ b。等),LINQ表达式树非常结构化。显然C#3系列编译器可以解析源代码来创建表达式,但是我不清楚(至少直到

Reflector支持CLR 3.5 ;-p)如何其中大部分是编译器和

运行时多少。


将字符串解析为表达式的能力非常好

功能强大......虽然如果解析外部实体,显然会有一些限制

条款......但是heck:只需访问

表达式参数和文字会非常强大。


也许我只是关闭一个......


Marc

Jon has correctly interpreted my witterings... my point being, that
unlike raw .Net 2.0 predicates (etc), LINQ expression trees are quite
structured. Obviously the C# 3-series compiler can parse source to
create an expression, but it is unclear to me (at least until
Reflector supports CLR 3.5 ;-p) how much of this is the compiler and
how much is the runtime.

The ability to parse a string to an expression would be very
powerful... although there would obviously be some limitations in
terms if resolving external entities... but heck: just access to the
expression arguments and literals would be pretty powerful.

Maybe I''m just "off on one"...

Marc


这篇关于LINQ的;表达式解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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