开发者

Convert lambda expression to string

This may seem like an odd request, however with APIs that require a filter property string I thought it would be a nice concept to be able to convert a provided typ开发者_高级运维e safe lambda expression which could then be compiled into a query string - similar in essence to Linq -> SQL.

So for example:

 Func<TQueryObj, bool> 
 (invoice) => { invoice.Status == "DRAFT" && invoice.Type == "ACCREF" };

Would convert to

 Status=="DRAFT" && Type=="ACCREF"

I'm using an invoicing API at the moment hence the example. Any means of achieving this fairly simply?

Cheers


You need to make an inherited ExpressionVisitor, which will recursively crawl through an Expression<Func<...>>.
It won't be easy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜