Coder Social home page Coder Social logo

Comments (6)

codingseb avatar codingseb commented on September 23, 2024 1

new version 1.4.30.0 introduce the this keyword to manage extention methods and indexing on Context.
Thanks @TheoVC.

from expressionevaluator.

TheoVC avatar TheoVC commented on September 23, 2024 1

Hi

Yes I tested and it's working perfectly fine. it's the perfect solution for indexing... and for calling context methods...

var Lista = new List<Person>() { new Person { Name = "uno", Value = 1.1m }, new Person { Name = "dos", Value = 2.2m } };

var Eval = new ExpressionEvaluator();
Eval.Context = Lista;
var temp = Eval.Evaluate("10.5m + this.Sum(x => x.Value) + this[0].Value");

Actually this code is in production already... :)

from expressionevaluator.

codingseb avatar codingseb commented on September 23, 2024

Hello @TheoVC I will try to correct this asap. Apparently it does'nt work when list is set as context but when I tested it with list set as variable it return an int. I just need to find why it doesnt work the same with context. I already know that indexing do not work with context so I think for now extensions methods either.

var Lista = new List<Test>() { new Test { Nombre = "uno", Valor = 1.11m }, new Test { Nombre = "uno", Valor = 2.22m }, new Test { Nombre = "uno", Valor = null }, new Test { Nombre = "dos", Valor = 3.33m } };
string script = "Lista.Sum(x => x.Nombre == \"uno\" ? (x.Valor ?? 0m) : 0m)";

ExpressionEvaluator Eval = new ExpressionEvaluator()
{
    CacheTypesResolutions = true
};

Eval.Variables["Lista"] = Lista;

var result = Eval.Evaluate(script);

Eval.Variables["Lista"] = Lista;

var result = Eval.Evaluate(script); //return 3

// ***********************************************************************
public class Test
{
     public string Nombre { get; set; }
     public decimal? Valor { get; set; }
}

from expressionevaluator.

TheoVC avatar TheoVC commented on September 23, 2024

Hello codingSeb

maybe if the keyword "this" could be introduced, and work as in regular c#
"this" refer to the Context, por example if the Context is an Array... you could evaluate something like this:

this[0]
this[0].Name

from expressionevaluator.

TheoVC avatar TheoVC commented on September 23, 2024

maybe the "this" keyword could work exactly like a variable... a default variable that is setted every time the Context is changed and point to the Context itself

from expressionevaluator.

codingseb avatar codingseb commented on September 23, 2024

Yes the this keyword idea is the solution because in C# we can not use extention methods neither inding on current object without this keyword. Thanks for your suggestion

from expressionevaluator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.