Exemplo n.º 1
0
        public static object FindValue(string from)
        {
            Type tp;
            var  value = StringUtils.ToPossibleValue(from, out tp);

            if (tp == typeof(string))
            {
                string   fieldName  = from;
                string[] fieldAcess = null;
                if (fieldName.Contains("."))
                {
                    var ac = fieldName.Split('.');
                    fieldAcess = new string[ac.Length - 1];
                    for (int i = 1; i < ac.Length; i++)
                    {
                        fieldAcess[i - 1] = ac[i];
                    }
                }
                var field = CODE_EXEC.GetField(fieldName);
                if (field != null)
                {
                    value = field.Value;
                    if (fieldAcess != null)
                    {
                        var vt = value.GetType();
                        foreach (var acess in fieldAcess)
                        {
                            if (!vt.IsPrimitive && vt != typeof(string))
                            {
                                var fld = vt.GetField(acess);
                                if (fld != null && !fld.FieldType.IsPrimitive && fld.FieldType != typeof(string))
                                {
                                    vt = fld.FieldType;
                                }
                                else
                                {
                                    value = fld.GetValue(value);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks the language routines.
        /// </summary>
        /// <param name="code">Code.</param>
        /// <param name="routineContext">Context Of This Routine,Script,Compilation or Static.</param>
        public static void CheckLanguageRoutines(string code, int routineContext = 0)
        {
            ScriptRoutineCheckContext context = (ScriptRoutineCheckContext)routineContext;

            if (code.Contains(CODE_INFO.LineSeparator.ToString()))
            {
                code = code.Replace(CODE_INFO.LineSeparator.ToString(), "");
            }
            if (code.Contains("Declare"))
            {
                if (code.Contains("var") && routineContext == 1)
                {
                    ScriptCompiler.Output.AddLog("This var declaration is invalid|2|10");
                }
                //var l = code.Split(' ');
                var l = StringUtils.CustomSplit(code, ' ', '"');
                if (l.Length >= 3)
                {
                    string      nameOf  = l[1];
                    string      valueOf = l[2];
                    ScriptField field   = new ScriptField(nameOf);
                    var         reads   = GetReads(valueOf, null);
                    field = SetFieldValue(field, reads);
                    var possibleField = CODE_EXEC.GetField(nameOf, context);
                    if (possibleField == null)
                    {
                        CODE_EXEC.RegisterField(field, context);
                    }
                }
            }
            if (code.Contains("Set"))
            {
                if (code.Contains("=") && routineContext == 1)
                {
                    ScriptCompiler.Output.AddLog("= in a wrong local|2|10");
                }
                var l = StringUtils.CustomSplit(code, ' ', '"');
                if (l.Length >= 4)
                {
                    string nameOf  = l[1];
                    string valueOf = l[3];
                    var    reads   = GetReads(valueOf, null);
                    CODE_EXEC.SetField(nameOf, reads);
                }
            }
        }
Exemplo n.º 3
0
        public static object[] GetReads(string code, string sep = "(,)", bool requireSemicolon = false)
        {
            if (!code.Contains(";") && requireSemicolon)
            {
                throw new Exception("This code has no ';' at the end");
            }
            var possibles = new string[0];

            if (sep != null)
            {
                string[] seps   = StringUtils.Split(sep, ",");
                var      after  = StringUtils.ReadAfter(code, seps[0]);
                var      inside = StringUtils.GetInside(code, seps[0], seps[1]);
                var      before = StringUtils.ReadBefore(code, seps[1]);
                possibles = inside.Split(' ');
            }
            else
            {
                possibles = code.Split(',');
            }
            List <object> vals = new List <object>();

            foreach (var possible in possibles)
            {
                //Type tp;
                var add = FindValue(possible);
                vals.Add(add);
            }
            object[] calls = vals.ToArray();
            int      index = 0;

            foreach (var call in calls)
            {
                string str = call + "";
                if (str != null)
                {
                    var field = CODE_EXEC.GetField(str);
                    if (field != null)
                    {
                        vals[index] = field.Value;
                    }
                }
                var add = calls[index];
                if (add is string)
                {
                    object prev = add;
                    //add = CODE_MATH.DoMath(add.ToString());
                    add = null;
                    if (add == null)
                    {
                        add = prev;
                    }
                    else
                    {
                        calls[index] = add;
                    }
                }
                index++;
            }
            return(calls);
        }