protected override void Initialize()
        {
            if (members != null)
            {
                return;
            }

            members = new Dictionary <SymbolId, List <ReflectedMember> >();

            MemberInfo[] infos = type.GetMembers();
            foreach (MemberInfo info in infos)
            {
                object[] attrs = info.GetCustomAttributes(typeof(IronPython.Runtime.PythonNameAttribute), false);
                if (attrs == null || attrs.Length == 0)
                {
                    continue;
                }
                IronPython.Runtime.PythonNameAttribute attr = attrs[0] as IronPython.Runtime.PythonNameAttribute;

                ReflectedMember md = CreateMemberDefinition(info);
                if (md != null)
                {
                    SymbolId name = SymbolTable.StringToId(attr.name);
                    List <ReflectedMember> list;
                    if (!members.TryGetValue(name, out list))
                    {
                        members[name] = list = new List <ReflectedMember>();
                    }
                    list.Add(md);
                }
            }
        }
Esempio n. 2
0
        public static string DocOneInfo(MethodBase info)
        {
            // Look for methods tagged with [Documentation("doc string for foo")]
            object[] attrs = info.GetCustomAttributes(typeof(DocumentationAttribute), false);
            if (attrs.Length > 0)
            {
                Debug.Assert(attrs.Length == 1);
                DocumentationAttribute doc = attrs[0] as DocumentationAttribute;
                return(doc.Value);
            }

            // Look for methods tagged with [PythonName("wellKnownMethodName")]
            attrs = info.GetCustomAttributes(typeof(PythonNameAttribute), false);
            if (attrs.Length > 0)
            {
                Debug.Assert(attrs.Length == 1);
                PythonNameAttribute pythonNameAttribute = attrs[0] as PythonNameAttribute;
                string defaultDoc = GetDefaultDocumentation(pythonNameAttribute.name);
                if (defaultDoc != null)
                {
                    return(defaultDoc);
                }
            }

            return(CreateAutoDoc(info));
        }