Exemplo n.º 1
0
        private IEnumerable <DocsNodeInfo> GetMembers(XmlDocument basefile, TypeDefinition type, FrameworkTypeEntry typeEntry)
        {
            while (ecmadocs.Name != "Members" && ecmadocs.Read())
            {
                // do nothing
            }
            if (ecmadocs.IsEmptyElement)
            {
                yield break;
            }

            int  membersDepth = ecmadocs.Depth;
            bool go           = true;

            while (go && ecmadocs.Read())
            {
                switch (ecmadocs.Name)
                {
                case "Member":
                {
                    if (membersDepth != ecmadocs.Depth - 1 || ecmadocs.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }
                    DocumentationMember dm = new DocumentationMember(ecmadocs);

                    string          xp        = MDocUpdater.GetXPathForMember(dm);
                    XmlElement      oldmember = (XmlElement)basefile.SelectSingleNode(xp);
                    MemberReference m;
                    if (oldmember == null)
                    {
                        m = GetMember(type, dm);
                        if (m == null)
                        {
                            app.Warning("Could not import ECMA docs for `{0}'s `{1}': Member not found.",
                                        type.FullName, dm.MemberSignatures["C#"]);
                            // SelectSingleNode (ecmaDocsMember, "MemberSignature[@Language=\"C#\"]/@Value").Value);
                            continue;
                        }
                        // oldmember lookup may have failed due to type parameter renames.
                        // Try again.
                        oldmember = (XmlElement)basefile.SelectSingleNode(MDocUpdater.GetXPathForMember(m));
                        if (oldmember == null)
                        {
                            XmlElement members = MDocUpdater.WriteElement(basefile.DocumentElement, "Members");
                            oldmember = basefile.CreateElement("Member");
                            oldmember.SetAttribute("MemberName", dm.MemberName);
                            members.AppendChild(oldmember);
                            foreach (string key in MDocUpdater.Sort(dm.MemberSignatures.Keys))
                            {
                                XmlElement ms = basefile.CreateElement("MemberSignature");
                                ms.SetAttribute("Language", key);
                                ms.SetAttribute("Value", (string)dm.MemberSignatures[key]);
                                oldmember.AppendChild(ms);
                            }
                            oldmember.SetAttribute("__monodocer-seen__", "true");
                            Console.WriteLine("Member Added: {0}", oldmember.SelectSingleNode("MemberSignature[@Language='C#']/@Value").InnerText);
                            app.additions++;
                        }
                    }
                    else
                    {
                        m = GetMember(type, new DocumentationMember(oldmember, typeEntry));
                        if (m == null)
                        {
                            app.Warning("Could not import ECMA docs for `{0}'s `{1}': Member not found.",
                                        type.FullName, dm.MemberSignatures["C#"]);
                            continue;
                        }
                        oldmember.SetAttribute("__monodocer-seen__", "true");
                    }
                    DocsNodeInfo node = new DocsNodeInfo(oldmember, m);
                    if (ecmadocs.Name != "Docs")
                    {
                        throw new InvalidOperationException("Found " + ecmadocs.Name + "; expected <Docs/>!");
                    }
                    yield return(node);

                    break;
                }

                case "Members":
                    if (membersDepth == ecmadocs.Depth && ecmadocs.NodeType == XmlNodeType.EndElement)
                    {
                        go = false;
                    }
                    break;
                }
            }
        }