//====================================================================
        // __repr__ implementation.
        //====================================================================

        public static new IntPtr tp_repr(IntPtr ob)
        {
            ModuleFunctionObject self = (ModuleFunctionObject)GetManagedObject(ob);
            string s = String.Format("<CLRModuleFunction '{0}'>", self.name);

            return(Runtime.PyString_FromStringAndSize(s, s.Length));
        }
Example #2
0
        /// <summary>
        /// Initialize module level functions and attributes
        /// </summary>
        internal void InitializeModuleMembers()
        {
            Type funcmarker = typeof(ModuleFunctionAttribute);
            Type propmarker = typeof(ModulePropertyAttribute);
            Type ftmarker   = typeof(ForbidPythonThreadsAttribute);
            Type type       = GetType();

            BindingFlags flags = BindingFlags.Public | BindingFlags.Static;

            while (type != null)
            {
                MethodInfo[] methods = type.GetMethods(flags);
                foreach (MethodInfo method in methods)
                {
                    object[] attrs         = method.GetCustomAttributes(funcmarker, false);
                    object[] forbid        = method.GetCustomAttributes(ftmarker, false);
                    bool     allow_threads = forbid.Length == 0;
                    if (attrs.Length > 0)
                    {
                        string name = method.Name;
                        var    mi   = new MethodInfo[1];
                        mi[0] = method;
                        var m = new ModuleFunctionObject(type, name, mi, allow_threads);
                        StoreAttribute(name, m);
                        m.DecrRefCount();
                    }
                }

                PropertyInfo[] properties = type.GetProperties();
                foreach (PropertyInfo property in properties)
                {
                    object[] attrs = property.GetCustomAttributes(propmarker, false);
                    if (attrs.Length > 0)
                    {
                        string name = property.Name;
                        var    p    = new ModulePropertyObject(property);
                        StoreAttribute(name, p);
                        p.DecrRefCount();
                    }
                }
                type = type.BaseType;
            }
        }
Example #3
0
        /// <summary>
        /// Initialize module level functions and attributes
        /// </summary>
        internal void InitializeModuleMembers()
        {
            Type funcmarker = typeof(ModuleFunctionAttribute);
            Type propmarker = typeof(ModulePropertyAttribute);
            Type ftmarker   = typeof(ForbidPythonThreadsAttribute);
            Type type       = this.GetType();

            BindingFlags flags = BindingFlags.Public | BindingFlags.Static;

            while (type != null)
            {
                MethodInfo[] methods = type.GetMethods(flags);
                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo method        = methods[i];
                    object[]   attrs         = method.GetCustomAttributes(funcmarker, false);
                    object[]   forbid        = method.GetCustomAttributes(ftmarker, false);
                    bool       allow_threads = (forbid.Length == 0);
                    if (attrs.Length > 0)
                    {
                        string       name = method.Name;
                        MethodInfo[] mi   = new MethodInfo[1];
                        mi[0] = method;
                        ModuleFunctionObject m = new ModuleFunctionObject(name, mi, allow_threads);
                        StoreAttribute(name, m);
                    }
                }

                PropertyInfo[] properties = type.GetProperties();
                for (int i = 0; i < properties.Length; i++)
                {
                    PropertyInfo property = properties[i];
                    object[]     attrs    = property.GetCustomAttributes(propmarker, false);
                    if (attrs.Length > 0)
                    {
                        string name            = property.Name;
                        ModulePropertyObject p = new ModulePropertyObject(property);
                        StoreAttribute(name, p);
                    }
                }
                type = type.BaseType;
            }
        }
Example #4
0
        /// <summary>
        /// Initialize module level functions and attributes
        /// </summary>
        internal void InitializeModuleMembers()
        {
            Type funcmarker = typeof(ModuleFunctionAttribute);
            Type propmarker = typeof(ModulePropertyAttribute);
            Type ftmarker = typeof(ForbidPythonThreadsAttribute);
            Type type = this.GetType();

            BindingFlags flags = BindingFlags.Public | BindingFlags.Static;

            while (type != null)
            {
                MethodInfo[] methods = type.GetMethods(flags);
                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo method = methods[i];
                    object[] attrs = method.GetCustomAttributes(funcmarker, false);
                    object[] forbid = method.GetCustomAttributes(ftmarker, false);
                    bool allow_threads = (forbid.Length == 0);
                    if (attrs.Length > 0)
                    {
                        string name = method.Name;
                        MethodInfo[] mi = new MethodInfo[1];
                        mi[0] = method;
                        ModuleFunctionObject m = new ModuleFunctionObject(type, name, mi, allow_threads);
                        StoreAttribute(name, m);
                    }
                }

                PropertyInfo[] properties = type.GetProperties();
                for (int i = 0; i < properties.Length; i++)
                {
                    PropertyInfo property = properties[i];
                    object[] attrs = property.GetCustomAttributes(propmarker, false);
                    if (attrs.Length > 0)
                    {
                        string name = property.Name;
                        ModulePropertyObject p = new ModulePropertyObject(property);
                        StoreAttribute(name, p);
                    }
                }
                type = type.BaseType;
            }
        }
        //====================================================================
        // __call__ implementation.
        //====================================================================

        public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
        {
            ModuleFunctionObject self = (ModuleFunctionObject)GetManagedObject(ob);

            return(self.Invoke(ob, args, kw));
        }