Example #1
0
        /// <summary>
        /// Get Method
        /// </summary>
        /// <remarks>
        /// Obtain the value of the variable of given name,
        /// and convert the result to a Managed Object of given type.
        /// If the variable does not exist, throw an Exception.
        /// </remarks>
        public T Get <T>(string name)
        {
            Check();
            PyObject pyObj = Get(name);

            if (pyObj == null)
            {
                return(default(T));
            }
            return(pyObj.As <T>());
        }
Example #2
0
        /// <summary>
        /// Execute method
        /// </summary>
        /// <remarks>
        /// Execute a Python ast and return the result as a PyObject,
        /// and convert the result to a Managed Object of given type.
        /// The ast can be either an expression or stmts.
        /// </remarks>
        public T Execute <T>(PyObject script, PyDict locals = null)
        {
            Check();
            PyObject pyObj = Execute(script, locals);

            if (pyObj == null)
            {
                return(default(T));
            }
            var obj = pyObj.As <T>();

            return(obj);
        }
 public static T T <T>(PyObject obj)
 {
     return(obj.As <T>());
 }
Example #4
0
 public override object ToClr(PyObject pyObj)
 {
     return(pyObj.As <double>());
 }
Example #5
0
 public override object ToClr(PyObject pyObj)
 {
     return(pyObj.As <float>());
 }
Example #6
0
 public override object ToClr(PyObject pyObj)
 {
     return(pyObj.As <long>());
 }