Exemple #1
0
        public static object GetValueObject(string name, bool NoResolve = false)
        {
            if (!NoResolve)
            {
                object dots = DotsResolver.Resolve(name);
                if (dots != null && dots.GetType() != typeof(VNull))
                {
                    if (dots.GetType() == typeof(EProperty))
                    {
                        return(((EProperty)dots).GetValue());
                    }
                    else if (dots.GetType() == typeof(EField))
                    {
                        return(((EField)dots).GetValue());
                    }
                    else if (dots.GetType() == typeof(EMethodNew))
                    {
                        return(((EMethodNew)dots).Invoke());
                    }
                    else
                    {
                        throw new Exception($"Excpeted field, but '{dots.GetType().Name}' received.");
                    }
                }
            }

            EVariable a = GetVariable(name);

            if (a == null)
            {
                return(new VNull());
            }

            return(a.Value);
        }
Exemple #2
0
        public static void SetVariable(string name, object value, List <string> options = null)
        {
            object dots = DotsResolver.Resolve(name);

            if (dots != null && dots.GetType() != typeof(VNull))
            {
                if (dots.GetType() == typeof(EProperty))
                {
                    ((EProperty)dots).SetValue(value);
                }
                else if (dots.GetType() == typeof(EField))
                {
                    ((EField)dots).SetValue(value);
                }
                else
                {
                    throw new Exception($"Excpeted field or method, but '{dots.GetType().Name}' received.");
                }
            }

            EVariable e = GetVariable(name);

            if (e == null)
            {
                EVariable variable = new EVariable(name, value, options);
                VarList.Add(variable);
            }
            else
            {
                if (e.Options.Contains("ReadOnly"))
                {
                    throw new Exception("ESCRIPT_ERROR_EDIT_READONLY_VARIABLE");
                }

                e.Edit(value, options);
            }
        }
        public static object InvokeMethod(string Name, object[] Arguments = null)
        {
            object m        = null;
            object instance = null;

            object dots = DotsResolver.Resolve(Name);

            if (dots != null && dots.GetType() != typeof(VNull))
            {
                if (dots.GetType() == typeof(EMethodNew))
                {
                    m = dots;
                }
            }

            foreach (var method in EnvironmentManager.AllMethods)
            {
                if (method.Name == Name)
                {
                    m = method;
                    goto invokeMethodStep;
                }
            }

invokeMethodStep:
            if (m == null)
            {
                throw new Exceptions.InvokeMethodNotFoundException($"Method '{Name}' is not found");
            }

            try
            {
                if (m.GetType() == typeof(EMethodNew))
                {
                    return(((EMethodNew)m).Invoke(Arguments));
                }
                else
                {
                    return(((MethodInfo)m).Invoke(instance, Arguments));
                }
            }
            catch (ArgumentException ex)
            {
                EConsole.WriteLine("ERROR: Invalid arguments", ConsoleColor.Red);
                Debug.DebugText(ex.ToString(), ConsoleColor.DarkRed);
                Process("UseTextTest(\"" + Name + "\");");// Call UseTextTest method to show arguments of command

                return(null);
            }
            catch (TargetInvocationException ex)
            {
                EConsole.WriteLine("ERROR: Can't invoke \"" + Name + "\" method because of exception:", ConsoleColor.Red);
                EConsole.WriteLine(ex.InnerException.ToString(), ConsoleColor.DarkRed);
                Process("UseTextTest(\"" + Name + "\");"); // Call UseTextTest method to show arguments of command

                return(null);                              // EResult.ESCRIPT.GetError("Exception");
            }
            catch (Exception ex)
            {
                EConsole.WriteLine(ex.GetType().Name + ": " + ex.Message, ConsoleColor.Red);
                Debug.DebugText(ex.StackTrace, ConsoleColor.DarkRed);
                Process("UseTextTest(\"" + Name + "\");"); // Call UseTextTest method to show arguments of command

                return(null);                              //EResult.Cmd.GetError(ex.Message);
            }
        }