chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using DynamicExpresso;
using OpenTap;
using OpenTap.Addin.Util;
using System;
 
namespace AddInPlugin.Util
{
    public class DefaultVariableResolver : IVariableResolver
    {
 
        private Interpreter GetInterpreter(TestPlanRun run, ITestStep step)
        {
            var target = new Interpreter();
            target.SetVariable("this", MethodUtil.Instance);
            target.SetVariable("FileGlobals", run?.FileGlobalsRuntime);
            target.SetVariable("StationGlobals", run?.StationGlobalsRuntime);
            target.SetVariable("Parameters", run?.ParametersRuntime);
 
            var context = step?.GetParent<ContextStep>();
            if (context != null)
            {
                target.SetVariable("Context", context.GetContextVariables());
            }
            return target;
        }
 
        public dynamic Resolve(TestPlanRun run, ITestStep step, string expr)
        {
            return Resolve(run, step, expr, typeof(void));
        }
 
        public T Resolve<T>(TestPlanRun run, ITestStep step, string expr)
        {
            return Resolve(run, step, expr, typeof(T));
        }
 
        public dynamic Resolve(TestPlanRun run, ITestStep step, string expr, Type targetType)
        {
            if (expr == null) return null;
            var target = GetInterpreter(run, step);
            if (targetType == typeof(string))
            {
                return target.Eval(expr)?.ToString();
            }
            return target.Eval(expr, targetType);
        }
    }
}