예제 #1
0
        /// <summary>
        /// Checks to see if the provided members are always visible for the given type.
        ///
        /// This filters out methods such as GetHashCode and Equals on standard .NET
        /// types that we expose directly as Python types (e.g. object, string, etc...).
        ///
        /// It also filters out the base helper overrides that are added for supporting
        /// super calls on user defined types.
        /// </summary>
        private static bool IsMethodAlwaysVisible(Type /*!*/ type, MemberInfo /*!*/[] /*!*/ methods)
        {
            bool alwaysVisible = true;

            if (PythonBinder.IsPythonType(type))
            {
                // only show methods defined outside of the system types (object, string)
                foreach (MethodInfo mi in methods)
                {
                    if (PythonBinder.IsExtendedType(mi.DeclaringType) ||
                        PythonBinder.IsExtendedType(mi.GetBaseDefinition().DeclaringType) ||
                        PythonHiddenAttribute.IsHidden(mi))
                    {
                        alwaysVisible = false;
                        break;
                    }
                }
            }
            else if (typeof(IPythonObject).IsAssignableFrom(type))
            {
                // check if this is a virtual override helper, if so we
                // may need to filter it out.
                foreach (MethodInfo mi in methods)
                {
                    if (PythonBinder.IsExtendedType(mi.DeclaringType))
                    {
                        alwaysVisible = false;
                        break;
                    }
                }
            }
            return(alwaysVisible);
        }
예제 #2
0
        internal static string GetModuleName(CodeContext /*!*/ context, Type type)
        {
            if (IsRuntimeAssembly(type.Assembly) || PythonBinder.IsPythonType(type))
            {
                Type curType = type;
                while (curType != null)
                {
                    string moduleName;
                    if (PythonContext.GetContext(context).BuiltinModuleNames.TryGetValue(curType, out moduleName))
                    {
                        return(moduleName);
                    }

                    curType = curType.DeclaringType;
                }

                FieldInfo modField = type.GetField("__module__");
                if (modField != null && modField.IsLiteral && modField.FieldType == typeof(string))
                {
                    return((string)modField.GetRawConstantValue());
                }
                return("__builtin__");
            }

            return(type.Namespace + " in " + type.Assembly.FullName);
        }