private Member LoadMember(Models.Type t, XElement mElement) { Member m = new Member(); m.Parent = t; m.Name = mElement.Attribute("MemberName").Value; m.ItemType = (ItemType)Enum.Parse(typeof(ItemType), mElement.Element("MemberType").Value); if (m.Name.StartsWith("op_") && m.ItemType == ItemType.Method) { m.ItemType = ItemType.Operator; } var memberValue = mElement.Element("MemberValue")?.Value; if (!string.IsNullOrEmpty(memberValue)) { m.Metadata[OPSMetadata.LiteralValue] = memberValue; } m.Signatures = new VersionedSignatures(mElement.Elements("MemberSignature"), m.ItemType); m.Modifiers = m.Signatures.CombinedModifiers; m.DocId = m.Signatures.DocId; m.AssemblyInfo = mElement.Elements("AssemblyInfo")?.SelectMany(a => ParseAssemblyInfo(a)).ToList(); //TypeParameters var tpElement = mElement.Element("TypeParameters"); if (tpElement != null) { m.TypeParameters = ParameterBase.LoadVersionedParameters <TypeParameter>(tpElement.Elements("TypeParameter")); } //Parameters var pElement = mElement.Element("Parameters"); if (pElement != null) { m.Parameters = ParameterBase.LoadVersionedParameters <Parameter>(pElement.Elements("Parameter")); } //Attributes var attrs = mElement.Element("Attributes"); if (attrs != null) { m.Attributes = attrs.Elements("Attribute").Select(a => LoadAttribute(a)).ToList(); } // Load monikerized return type data var returnValueElement = mElement.Element("ReturnValue"); m.ReturnValueType = MonikerizeReturnValue(returnValueElement); var implements = mElement.Element("Implements"); if (implements != null) { m.Implements = implements.Elements("InterfaceMember")?.Select(LoadMonikerizedValue).ToList(); } //Docs m.Docs = LoadDocs(mElement.Element("Docs"), t.SourceFileLocalPath); LoadMetadata(m, mElement); return(m); }
private Models.Type LoadType(FileItem typeFile) { string xmlContent = _fileAccessor.ReadAllText(typeFile.RelativePath); xmlContent = xmlContent.Replace("TextAntiAliasingQuality property.</summary>", "TextAntiAliasingQuality property.</summary>"); xmlContent = xmlContent.Replace("DefaultValue('�')</AttributeName>", "DefaultValue('\\0')</AttributeName>"); xmlContent = xmlContent.Replace("\0", "\\0"); XDocument tDoc = XDocument.Parse(xmlContent, LoadOptions.PreserveWhitespace); XElement tRoot = tDoc.Root; if (tRoot.Name.LocalName != "Type") { return(null); } Models.Type t = new Models.Type(); t.Name = tRoot.Attribute("Name").Value.Replace('+', '.'); t.FullName = tRoot.Attribute("FullName").Value.Replace('+', '.'); t.SourceFileLocalPath = typeFile.AbsolutePath; //TypeSignature t.Signatures = new VersionedSignatures(tRoot.Elements("TypeSignature")); t.Modifiers = t.Signatures.CombinedModifiers; t.DocId = t.Signatures.DocId; //AssemblyInfo t.AssemblyInfo = tRoot.Elements("AssemblyInfo")?.SelectMany(a => ParseAssemblyInfo(a)).ToList(); //TypeParameters var tpElement = tRoot.Element("TypeParameters"); if (tpElement != null) { t.TypeParameters = ParameterBase.LoadVersionedParameters <TypeParameter>(tpElement.Elements("TypeParameter")); } //Parameters var pElement = tRoot.Element("Parameters"); if (pElement != null) { t.Parameters = ParameterBase.LoadVersionedParameters <Parameter>(pElement.Elements("Parameter")); } var rvalElement = tRoot.Element("ReturnValue"); if (rvalElement != null) { t.ReturnValueType = MonikerizeReturnValue(rvalElement); } //BaseTypeName t.BaseTypes = LoadBaseType(tRoot.Element("Base")); //Interfaces var interfacesElement = tRoot.Element("Interfaces"); if (interfacesElement != null) { t.Interfaces = interfacesElement.Elements("Interface") .Select(i => new VersionedString(LoadFrameworkAlternate(i), i?.Element("InterfaceName")?.Value)) .ToList(); } //Attributes var attrs = tRoot.Element("Attributes"); if (attrs != null) { t.Attributes = attrs.Elements("Attribute").Select(a => LoadAttribute(a)).ToList(); } //TypeForwardingChain var forwardingChain = tRoot.Element("TypeForwardingChain"); if (forwardingChain != null) { var fwds = forwardingChain.Elements("TypeForwarding").Select(fwd => LoadTypeForwarding(fwd)).ToList(); t.TypeForwardingChain = new TypeForwardingChain(fwds); } //Members var membersElement = tRoot.Element("Members"); if (membersElement != null) { t.Members = membersElement.Elements("Member")?.Select(m => LoadMember(t, m)).ToList(); t.Members.Sort((m1, m2) => { if (m1.IsEII == m2.IsEII) { return(string.Compare(m1.Name, m2.Name)); } else { return(m1.IsEII ? 1 : -1); //non-EII first, EII later } }); if (t.Members != null) { foreach (var m in t.Members) { m.SourceFileLocalPath = typeFile.AbsolutePath; } } t.Overloads = membersElement.Elements("MemberGroup")?.Select(m => LoadMemberGroup(t, m)).ToList(); if (t.Overloads != null) { var distinctList = new List <Member>(); foreach (var og in t.Overloads.GroupBy(o => o.Name)) { if (og.Count() > 1) { OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_MemberGroup_Duplicated, typeFile.AbsolutePath, og.Key); } og.First().SourceFileLocalPath = typeFile.AbsolutePath; distinctList.Add(og.First()); } t.Overloads = distinctList; } } //Docs t.Docs = LoadDocs(tRoot.Element("Docs"), typeFile.AbsolutePath); //MemberType t.ItemType = InferTypeOfType(t); if (t.ItemType == ItemType.Enum && t.Members?.Count > 0) { foreach (var m in t.Members) { if (!string.IsNullOrEmpty(m.Docs.Remarks)) { OPSLogger.LogUserSuggestion(LogCode.ECMA2Yaml_Enum_NoRemarks, typeFile.AbsolutePath); } } } // Metadata LoadMetadata(t, tRoot); return(t); }