Наследование: MethodObject
Пример #1
0
        /// <summary>
        /// Given a newly allocated Python type object and a managed Type that
        /// implements it, initialize any methods defined by the Type that need
        /// to appear in the Python type __dict__ (based on custom attribute).
        /// </summary>
        private static void InitMethods(IntPtr pytype, Type type)
        {
            IntPtr dict   = Marshal.ReadIntPtr(pytype, TypeOffset.tp_dict);
            Type   marker = typeof(PythonMethodAttribute);

            BindingFlags flags        = BindingFlags.Public | BindingFlags.Static;
            var          addedMethods = new HashSet <string>();

            while (type != null)
            {
                MethodInfo[] methods = type.GetMethods(flags);
                foreach (MethodInfo method in methods)
                {
                    if (!addedMethods.Contains(method.Name))
                    {
                        object[] attrs = method.GetCustomAttributes(marker, false);
                        if (attrs.Length > 0)
                        {
                            string method_name = method.Name;
                            var    mi          = new MethodInfo[1];
                            mi[0] = method;
                            MethodObject m = new TypeMethod(type, method_name, mi);
                            Runtime.PyDict_SetItemString(dict, method_name, m.pyHandle);
                            addedMethods.Add(method_name);
                        }
                    }
                }
                type = type.BaseType;
            }
        }
Пример #2
0
        //====================================================================
        // Given a newly allocated Python type object and a managed Type that
        // implements it, initialize any methods defined by the Type that need
        // to appear in the Python type __dict__ (based on custom attribute).
        //====================================================================

        private static void InitMethods(IntPtr pytype, Type type)
        {
            IntPtr dict   = Marshal.ReadIntPtr(pytype, TypeOffset.tp_dict);
            Type   marker = typeof(PythonMethodAttribute);

            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(marker, false);
                    if (attrs.Length > 0)
                    {
                        string       method_name = method.Name;
                        MethodInfo[] mi          = new MethodInfo[1];
                        mi[0] = method;
                        MethodObject m = new TypeMethod(method_name, mi);
                        Runtime.PyDict_SetItemString(dict, method_name,
                                                     m.pyHandle);
                    }
                }
                type = type.BaseType;
            }
        }
Пример #3
0
        //====================================================================
        // Given a newly allocated Python type object and a managed Type that
        // implements it, initialize any methods defined by the Type that need
        // to appear in the Python type __dict__ (based on custom attribute).
        //====================================================================

        private static void InitMethods(IntPtr pytype, Type type) {
            IntPtr dict = Marshal.ReadIntPtr(pytype, TypeOffset.tp_dict);
            Type marker = typeof(PythonMethodAttribute);

            BindingFlags flags = BindingFlags.Public | BindingFlags.Static;
            HashSet<string> addedMethods = new HashSet<string>();

            while (type != null) {
                MethodInfo[] methods = type.GetMethods(flags);
                for (int i = 0; i < methods.Length; i++) {
                    MethodInfo method = methods[i];
                    if (!addedMethods.Contains(method.Name)) {
                        object[] attrs = method.GetCustomAttributes(marker, false);
                        if (attrs.Length > 0) {
                            string method_name = method.Name;
                            MethodInfo[] mi = new MethodInfo[1];
                            mi[0] = method;
                            MethodObject m = new TypeMethod(type, method_name, mi);
                            Runtime.PyDict_SetItemString(dict, method_name, m.pyHandle);
                            addedMethods.Add(method_name);
                        }
                    }
                }
                type = type.BaseType;
            }
        }