zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
449 stars 86 forks source link

Strange return value with "_context" #115

Closed cuiliang closed 2 years ago

cuiliang commented 3 years ago

https://dotnetfiddle.net/6IEtGc

code:

// @nuget: Z.Expressions.Eval

using System;
using Z.Expressions;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        // From simple expression...

        var dict = new Dictionary<string, object>();
        dict.Add("_context", "aaa");
        // To complex code.
        var result = Eval.Execute("\"_context\"", dict);

        Console.WriteLine(result);      

    }
}

returns zzz_f900d830_3564_44fc_a449_570a57c64ff5 which should return a string _context .

image

cuiliang commented 3 years ago

remove _ from variable name will return correct result.

JonathanMagnan commented 3 years ago

Hello @cuiliang ,

Thank you for reporting, we will look at it.

Best Regards,

Jon

JonathanMagnan commented 2 years ago

Hello @cuiliang ,

Unfortunately, we still have not succeeded to fix this issue correctly without getting some side impact as we know some people use that feature in their code (Dict key is replaced by value).

However, we choose to add an option to disable this behavior as we understand not everyone wants it and as you show, it cause also some impact.

You can disable it with the options DisableAutoReplaceDictionaryKey = true.

We will not close this issue as we might want to try it again but for now, using that new option will be the solution for this behavior.

cuiliang commented 2 years ago

Thank you! Got it~

Jonathan Magnan @.***> 于2021年10月28日周四 上午12:21写道:

Hello @cuiliang https://github.com/cuiliang ,

Unfortunately, we still have not succeeded to fix this issue correctly without getting some side impact as we know some people use that feature in their code (Dict key is replaced by value).

However, we choose to add an option to disable this behavior as we understand not everyone wants it and as you show, it cause also some impact.

You can disable it with the options DisableAutoReplaceDictionaryKey = true .

We will not close this issue as we might want to try it again but for now, using that new option will be the solution for this behavior.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zzzprojects/Eval-Expression.NET/issues/115#issuecomment-953090568, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPBTKNLIXY3MBZGC3X4RVDUJARKLANCNFSM5E42TVVA .