nreco / lambdaparser

Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.
http://www.nrecosite.com/
MIT License
307 stars 55 forks source link

enable read constants #11

Closed Jiuyong closed 6 years ago

Jiuyong commented 7 years ago

It can't read the Value ,when it is ConstantExpression .

VitaliyMF commented 7 years ago

Could you explain your changes / motivation / usage scenario a bit? As I understand you need to access constants inside Expression composed by LamdbaParser (for some reason). I believe that LambdaWrapper should remain internal as it is essential part of the internal logic.

Alternative to your changes: move explicit cast operators to LambdaWrapper.cs and possibly introduce public ILambdaValue interface that exposes real value for external usage (smth like object Value { get; } ).

Jiuyong commented 7 years ago

yes ,wo know you went why you remain internal as LambdaWrapper . but ,in another way,if you went use LambdaWrapper.Parse() mathod not LambdaWrapper.Eval to do something. for example,in may way ,i use LambdaWrapper to parse lambda not to use it as C# .i need to convert it to Elasticsearch query ,like LinqToElastic . so , i use your NuGet can't work . at the end ,i to do this...

and...where is ILambdaValue ?

Jiuyong commented 7 years ago

and we try change the code : can read the Value and keep it internal .but ,i can't to do it. can u have a better idea ?

VitaliyMF commented 7 years ago

@Jiuyong I'm trying to understand your needs and propose better solution than in your pull request.

for example,in may way ,i use LambdaWrapper to parse lambda not to use it as C# .i need to convert it to Elasticsearch query ,like LinqToElastic .

possibly this is improper use of LambdaParser: it is intended for evaluation of c#-like expressions in run-time; it supports a lot of features (method invocations, property/indexer accessors) that rely on .NET and cannot be translated to database query like Elastic or MongoDb.

If you're looking for parser for user-defined filters to database, take a look to the RelexParser from NReco.Data library: it can parse simple expressions with conditions + and/or into special Query structure that can be translated to SQL (this is already implemented in the library) or NoSQL query (like ElasticSearch in your case).

Jiuyong commented 7 years ago

我需要处理的不是一个简单的表达式,而是一个复杂的。你提到的这些组件是能处理简单的运算,扩展性比较差。这也是为什么我会用到你写的组件的原因。

I need is not a simple process of expressions, but a complex. You mentioned that these components are capable of handling simple operation, relatively poor scalability. This is the reason why I use the components you write.

Jiuyong commented 7 years ago

For I am so poor English I have to give up, instead of using Machine Translation now, hope you don't mind. I mean, you have to run this component is the expression function, this is the characteristic of great. But this component has a very good characteristic, is the expression can be parsed into expressions tree. Using this feature, can achieve their own custom expression action. Rather than just run it. For example my needs, is the need of the expression as I wanted to explain.

对于我这么差的英文我已经放弃了,现在使用机器翻译代替,希望你不要介意。我原来的意思是,你的这个组件是有运行表达式的功能的,这个是非常棒的特性。但是其实这个组件还有个非常棒的特性,是可以将表达式解析成表达式树。利用这个特性,可以实现自己定制的实现表达式的动作。而不是仅仅局限于运行它。例如我的需求里面,就是需要将表达式按照自己想要的方式来解释。

VitaliyMF commented 7 years ago

@Jiuyong I guess I understand your needs; I cannot accept your pull request as it makes LambdaParameterWrapper public and I believe that it should remain internal. Instead of that I can add ILambdaValue interface to allow access to the constant values wrapped with LambdaParameterWrapper.

Jiuyong commented 5 years ago

how can i access to the constant values ?

VitaliyMF commented 5 years ago

@Jiuyong At this moment you can't. In my answer - from Aug 1 2017 - I've proposed how this might be possible (with ILambdaValue interface) but you disappeared.

Jiuyong commented 5 years ago

your means i do it ?

VitaliyMF commented 5 years ago

@Jiuyong I mean that you created an issue more than year ago, then I proposed to introduce smth like ILambdaValue but didn't get any response from you and closed the issue (if you don't need this change, no reason to do it).