GetPythonType() public static méthode

public static GetPythonType ( DynamicMetaObject value ) : IronPython.Runtime.Types.PythonType
value System.Dynamic.DynamicMetaObject
Résultat IronPython.Runtime.Types.PythonType
Exemple #1
0
        /// <summary>
        /// Determines if the type associated with the first MetaObject is a subclass of the
        /// type associated with the second MetaObject.
        /// </summary>
        internal static bool IsSubclassOf(DynamicMetaObject /*!*/ xType, DynamicMetaObject /*!*/ yType)
        {
            PythonType x = MetaPythonObject.GetPythonType(xType);
            PythonType y = MetaPythonObject.GetPythonType(yType);

            return(x.IsSubclassOf(y));
        }
        internal static DynamicMetaObject ConvertToIEnumerator(DynamicMetaObjectBinder /*!*/ conversion, DynamicMetaObject /*!*/ metaUserObject)
        {
            PythonType     pt      = MetaPythonObject.GetPythonType(metaUserObject);
            PythonContext  state   = PythonContext.GetPythonContext(conversion);
            CodeContext    context = state.SharedContext;
            PythonTypeSlot pts;


            if (pt.TryResolveSlot(context, "__iter__", out pts))
            {
                ParameterExpression tmp = Ast.Parameter(typeof(object), "iterVal");

                return(new DynamicMetaObject(
                           Expression.Block(
                               new[] { tmp },
                               Expression.Call(
                                   typeof(PythonOps).GetMethod("CreatePythonEnumerator"),
                                   Ast.Block(
                                       MetaPythonObject.MakeTryGetTypeMember(
                                           state,
                                           pts,
                                           metaUserObject.Expression,
                                           tmp
                                           ),
                                       Ast.Dynamic(
                                           new PythonInvokeBinder(
                                               state,
                                               new CallSignature(0)
                                               ),
                                           typeof(object),
                                           AstUtils.Constant(context),
                                           tmp
                                           )
                                       )
                                   )
                               ),
                           metaUserObject.Restrictions
                           ));
            }
            else if (pt.TryResolveSlot(context, "__getitem__", out pts))
            {
                return(MakeGetItemIterable(metaUserObject, state, pts, "CreateItemEnumerator"));
            }

            return(null);
        }
        internal static DynamicMetaObject ConvertToIEnumerable(DynamicMetaObjectBinder /*!*/ conversion, DynamicMetaObject /*!*/ metaUserObject)
        {
            PythonType     pt        = MetaPythonObject.GetPythonType(metaUserObject);
            PythonContext  pyContext = PythonContext.GetPythonContext(conversion);
            CodeContext    context   = pyContext.SharedContext;
            PythonTypeSlot pts;

            if (pt.TryResolveSlot(context, "__iter__", out pts))
            {
                return(MakeIterRule(metaUserObject, "CreatePythonEnumerable"));
            }
            else if (pt.TryResolveSlot(context, "__getitem__", out pts))
            {
                return(MakeGetItemIterable(metaUserObject, pyContext, pts, "CreateItemEnumerable"));
            }

            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Tries to get the BuiltinFunction for the given name on the type of the provided MetaObject.
        ///
        /// Succeeds if the MetaObject is a BuiltinFunction or BuiltinMethodDescriptor.
        /// </summary>
        internal static bool TryGetStaticFunction(PythonContext /*!*/ state, string op, DynamicMetaObject /*!*/ mo, out BuiltinFunction function)
        {
            PythonType type = MetaPythonObject.GetPythonType(mo);

            function = null;
            if (!String.IsNullOrEmpty(op))
            {
                PythonTypeSlot xSlot;
                object         val;
                if (type.TryResolveSlot(state.SharedContext, op, out xSlot) &&
                    xSlot.TryGetValue(state.SharedContext, null, type, out val))
                {
                    function = TryConvertToBuiltinFunction(val);
                    if (function == null)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }