Beispiel #1
0
        public static TReturn CallMethod <TReturn>(string variableName, string methodName, params object[] args)
        {
            try
            {
                ObjectOperations ops = _engine.Operations;
                if (_scope.ContainsVariable(variableName))
                {
                    object instance = _scope.GetVariable(variableName);
                    if (instance != null)
                    {
                        if (ops.ContainsMember(instance, methodName))
                        {
                            object method = ops.GetMember(instance, methodName);
                            return((TReturn)ops.Call(method, args));
                        }
                    }
                }
                return(default(TReturn));
            }
            catch (Exception ex)
            {
#if DEBUG
                throw ex;
#else
                Log.Write(LogType.Error, ex.ToString());
                return(default(TReturn));
#endif
            }
        }
Beispiel #2
0
        public static void Call(string className, string methodName, params object[] args)
        {
            ObjectOperations ops = _engine.Operations;

            if (_scope.ContainsVariable(className))
            {
                object @class   = _scope.GetVariable(className);
                object instance = ops.Call(@class);
                if (instance != null)
                {
                    if (ops.ContainsMember(instance, methodName))
                    {
                        object method = ops.GetMember(instance, methodName);
                        ops.Call(method, args);
                    }
                }
            }
        }
Beispiel #3
0
        public static T CreateInstance <T>(string name)
        {
            ObjectOperations ops    = _engine.Operations;
            object           @class = _engine.GetVariable(_scope, name);

            if (@class != null)
            {
                object instance = ops.Call(@class);
                return((T)instance);
            }
            return(default(T));
        }
        /// <summary>
        /// Gets the results of an IronPython file after execution.
        /// </summary>
        /// <typeparam name="EngineResults">Generic result from IronPython class.</typeparam>
        /// <param name="className">The name of the class to reference.</param>
        /// <param name="methodName">The name of the method to execute.</param>
        /// <returns>The results of IronPython execution.</returns>
        public EngineResults Execute <EngineResults>(string className, string methodName)
        {
            source.Execute(scope);
            var classObj      = scope.GetVariable(className);
            var classInstance = operations.Call(classObj);
            var classMethod   = operations.GetMember(classInstance, methodName);
            var results       = (EngineResults)operations.Call(classMethod);

            return(results);
        }
Beispiel #5
0
        public static void CallGlobalMethod(string methodName, params object[] args)
        {
            try
            {
                ObjectOperations ops = _engine.Operations;
                if (_scope.ContainsVariable(methodName))
                {
                    ops.Call(_scope.GetVariable(methodName), args);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                throw ex;
#else
                Log.Write(LogType.Error, ex.ToString());
#endif
            }
        }