예제 #1
0
        public T Evaluate(object host, IDictionary <string, object> variables = null)
        {
            var vars = new Dictionary <string, object>(variables ?? new Dictionary <string, object>());

            vars.Add("self", Context);
            vars.Add("host", host);
            if (host is IFormulaHost)
            {
                foreach (var kvp in ((IFormulaHost)host).Variables)
                {
                    vars.Add(kvp.Key, kvp.Value);
                }
            }
            if (host is IModObject mo)
            {
                if (mo.TemplateParameters != null)
                {
                    foreach (var kvp in mo.TemplateParameters)
                    {
                        vars.Add(kvp.Key, kvp.Value);
                    }
                }
            }
            string fulltext;

            if (ExternalScripts == null)
            {
                fulltext = Text;
            }
            else
            {
                fulltext = string.Join("\n", ExternalScripts.Select(q => q.Text)) + "\n" + Text;
            }
            return(PythonScriptEngine.EvaluateExpression <T>(fulltext, vars));
        }
예제 #2
0
파일: MetaRecord.cs 프로젝트: ekolis/FrEee
        private static Field CreateStaticFormulaField(Field f, IDictionary <string, int> args)
        {
            var variables = args.ToDictionary(kvp => kvp.Key, kvp => (object)kvp.Value);
            var result    = PythonScriptEngine.EvaluateExpression <IConvertible>(f.Value.TrimStart('='), variables).ToStringInvariant();
            var field     = new Field();

            field.Name  = f.Name;
            field.Value = result;
            return(field);
        }