当前位置: 首页>>代码示例>>C#>>正文


C# XContainer.Descendants方法代码示例

本文整理汇总了C#中System.Xml.Linq.XContainer.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# XContainer.Descendants方法的具体用法?C# XContainer.Descendants怎么用?C# XContainer.Descendants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XContainer的用法示例。


在下文中一共展示了XContainer.Descendants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OpenCoverParser

        /// <summary>
        /// Initializes a new instance of the <see cref="OpenCoverParser"/> class.
        /// </summary>
        /// <param name="report">The report file as XContainer.</param>
        internal OpenCoverParser(XContainer report)
        {
            if (report == null)
            {
                throw new ArgumentNullException(nameof(report));
            }

            this.modules = report.Descendants("Module")
                .Where(m => m.Attribute("skippedDueTo") == null)
                .ToArray();
            this.files = report.Descendants("File").ToArray();
            this.trackedMethods = report.Descendants("TrackedMethod")
                .ToDictionary(t => t.Attribute("uid").Value, t => t.Attribute("name").Value);

            var assemblyNames = this.modules
                .Select(m => m.Element("ModuleName").Value)
                .Distinct()
                .OrderBy(a => a)
                .ToArray();

            Parallel.ForEach(assemblyNames, assemblyName => this.AddAssembly(this.ProcessAssembly(assemblyName)));

            this.modules = null;
            this.files = null;
            this.trackedMethods = null;
        }
开发者ID:tigerjibo,项目名称:ReportGenerator,代码行数:30,代码来源:OpenCoverParser.cs

示例2: PartCover22Parser

        /// <summary>
        /// Initializes a new instance of the <see cref="PartCover22Parser"/> class.
        /// </summary>
        /// <param name="report">The report file as XContainer.</param>
        public PartCover22Parser(XContainer report)
            : base(report)
        {
            // Init the HashSet containing the covered assemblies
            this.assembliesHashSet = new HashSet<string>(report.Descendants("type").Select(type => type.Attribute("asm").Value).Distinct());

            var fileIdByFilenameDictionary = report.Descendants("file").ToDictionary(f => f.Attribute("url").Value, f => f.Attribute("id").Value);

            AddCoverageDataOfAutoProperties(report);

            // Init the Dictionary containing the line coverage information
            Parallel.ForEach(
                this.Assemblies(),
                assembly =>
                {
                    logger.DebugFormat("  Current Assembly: {0}", assembly);

                    Parallel.ForEach(
                        this.ClassesInAssembly(assembly),
                        clazz =>
                        {
                            Parallel.ForEach(
                                this.FilesOfClass(assembly, clazz),
                                file =>
                                {
                                    string fileId = fileIdByFilenameDictionary[file];

                                    var seqpntsOfFile = report.Descendants("type")
                                        .Where(type => type.Attribute("asm").Value.Equals(assembly) && type.Attribute("name").Value.StartsWith(clazz, StringComparison.Ordinal))
                                        .Descendants("pt")
                                        .Where(seqpnt => seqpnt.HasAttributeWithValue("fid", fileId))
                                        .OrderBy(seqpnt => int.Parse(seqpnt.Attribute("sl").Value, CultureInfo.InvariantCulture))
                                        .ToArray();

                                    if (seqpntsOfFile.Length > 0)
                                    {
                                        var coverage = new int[int.Parse(seqpntsOfFile.Last().Attribute("sl").Value, CultureInfo.InvariantCulture) + 1];

                                        for (int i = 0; i < coverage.Length; i++)
                                        {
                                            coverage[i] = -1;
                                        }

                                        foreach (var seqpnt in seqpntsOfFile)
                                        {
                                            var index = int.Parse(seqpnt.Attribute("sl").Value, CultureInfo.InvariantCulture);
                                            var value = int.Parse(seqpnt.Attribute("visit").Value, CultureInfo.InvariantCulture);
                                            coverage[index] = coverage[index] == -1 ? value : coverage[index] + value;
                                        }

                                        this.LineCoverageByFileDictionary.TryAdd(assembly + "_" + clazz + "_" + file, coverage);
                                    }
                                });
                        });
                });
        }
开发者ID:kchittiprolu,项目名称:Text-Format-Application,代码行数:60,代码来源:PartCover22Parser.cs

示例3: AclEntry

 public AclEntry(XContainer element)
 {
     AclPermission permission;
     Permission =
         Enum.TryParse(element.Descendants("Permission").Select(e => e.Value).FirstOrDefault() ?? String.Empty,
                       out permission)
             ? permission
             : AclPermission.READ;
     Scope = ScopeBuilder.CreateScope(element.Descendants("Scope").First());
 }
开发者ID:acropolium,项目名称:SharpGs,代码行数:10,代码来源:AclEntry.cs

示例4: ReadResults

		void ReadResults(XContainer reader)
		{
			IEnumerable<XElement> modules = reader.Descendants("Module").Where(m => m.Attribute("skippedDueTo") == null);
			foreach (XElement file in reader.Descendants("File")) {
				AddFileName(file);
			}
			foreach (XElement assembly in modules) {
				AddAssembly(assembly);
				RegisterAssembly(assembly);
			}
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:11,代码来源:CodeCoverageResults.cs

示例5: NCoverParser

        /// <summary>
        /// Initializes a new instance of the <see cref="NCoverParser"/> class.
        /// </summary>
        /// <param name="report">The report file as XContainer.</param>
        public NCoverParser(XContainer report)
            : base(report)
        {
            // Init the HashSet containing the covered assemblies
            this.assembliesHashSet = new HashSet<string>(report.Descendants("module").Select(module => module.Attribute("assembly").Value));

            // Init the Dictionary containing the line coverage information
            Parallel.ForEach(
                this.Assemblies(),
                (assembly) =>
                {
                    logger.DebugFormat("  Current Assembly: {0}", assembly);

                    Parallel.ForEach(
                        this.ClassesInAssembly(assembly),
                        (clazz) =>
                        {
                            Parallel.ForEach(
                                this.FilesOfClass(assembly, clazz),
                                (file) =>
                                {
                                    var seqpntsOfFile = report.Descendants("module")
                                        .Where(type => type.Attribute("assembly").Value.Equals(assembly))
                                        .Elements("method").Where(method => method.Attribute("class").Value.StartsWith(clazz, StringComparison.Ordinal))
                                        .Descendants("seqpnt")
                                        .Where(seqpnt => seqpnt.Attribute("document").Value.Equals(file) && seqpnt.Attribute("line").Value != "16707566")
                                        .OrderBy(seqpnt => int.Parse(seqpnt.Attribute("line").Value, CultureInfo.InvariantCulture))
                                        .ToArray();

                                    if (seqpntsOfFile.Length > 0)
                                    {
                                        var coverage = new int[int.Parse(seqpntsOfFile.Last().Attribute("line").Value, CultureInfo.InvariantCulture) + 1];

                                        for (int i = 0; i < coverage.Length; i++)
                                        {
                                            coverage[i] = -1;
                                        }

                                        foreach (var seqpnt in seqpntsOfFile)
                                        {
                                            var index = int.Parse(seqpnt.Attribute("line").Value, CultureInfo.InvariantCulture);
                                            var value = int.Parse(seqpnt.Attribute("visitcount").Value, CultureInfo.InvariantCulture);
                                            coverage[index] = coverage[index] == -1 ? value : coverage[index] + value;
                                        }

                                        this.LineCoverageByFileDictionary.TryAdd(assembly + "_" + clazz + "_" + file, coverage);
                                    }
                                });
                        });
                });
        }
开发者ID:kchittiprolu,项目名称:Text-Format-Application,代码行数:55,代码来源:NCoverParser.cs

示例6: TryParse

        public static bool TryParse(XContainer xml, out GoodreadsBook result)
        {
            result = null;

            var bookNode = (xml is XElement && (xml as XElement).Name == "best_book") ? xml as XElement : xml.Descendants("best_book").FirstOrDefault();
            var idNode = (bookNode.Element("id")?.FirstNode as XText)?.Value;
            var titleNode = bookNode.Element("title");
            var authorNode = bookNode.Element("author");

            var title = titleNode?.Value;
            if (string.IsNullOrEmpty(title))
            {
                return false;
            }

            int id;
            if (idNode == null || !int.TryParse(idNode, out id))
            {
                id = int.MinValue;
            }

            GoodreadsAuthor author;
            if (authorNode == null || !GoodreadsAuthor.TryParse(authorNode, out author))
            {
                result = new GoodreadsBook(id, title);
            }
            else
            {
                result = new GoodreadsBook(id, title, author);
            }

            return true;
        }
开发者ID:saqneo,项目名称:ReadingList,代码行数:33,代码来源:GoodreadsBook.cs

示例7: DeserializeAll

        public static IEnumerable<UserSettings> DeserializeAll(XContainer container)
        {
            if (container == null)
                throw new ArgumentNullException("xml");

            return from x in container.Descendants("UserSettings") select Deserialize(x);
        }
开发者ID:baughj,项目名称:Spark,代码行数:7,代码来源:UserSettingsSerializer.cs

示例8: SetStaticProfiles

        public static void SetStaticProfiles(XContainer transform, XContainer presentation)
        {
            string baseUri = "http://www.w3.org/ns/ttml/feature";

            var features = from f in transform.Descendants("{http://www.w3.org/ns/ttml#parameter}feature")
                           select new FeatureValue
                           {
                               Required = f.Attribute("value").Value == "required",
                               Label = f.Value
                           };
            m_transformProfile.Clear();
            foreach (var f in features)
            {
                m_transformProfile.Add(baseUri + f.Label, f.Required);
            }

            features = from f in presentation.Descendants("{http://www.w3.org/ns/ttml#parameter}feature")
                       select new FeatureValue
                       {
                           Required = f.Attribute("value").Value == "required",
                           Label = f.Value
                       };
            m_presentationProfile.Clear();
            foreach (var f in features)
            {
                m_presentationProfile.Add(baseUri + f.Label, f.Required);
            }
        }
开发者ID:bondarenkod,项目名称:pf-arm-deploy-error,代码行数:28,代码来源:TimedTextProfile.cs

示例9: ParseIssues

        private List<ValidationIssue> ParseIssues(XContainer document, string rootName, string listName, string tagName, Severity severity)
        {
            var elements = from e in document.Descendants(_namespace + rootName) select e;
            var issues = new List<ValidationIssue>();

            foreach (var element in elements)
            {
                foreach (var list in element.Descendants(_namespace + listName))
                {
                    foreach (var errorElement in list.Descendants(_namespace + tagName))
                    {
                        var issue = new ValidationIssue { Severity = severity };

                        if (errorElement.Descendants(_namespace + "line").Any())
                            issue.Row = int.Parse(errorElement.Descendants(_namespace + "line").First().Value);
                        if (errorElement.Descendants(_namespace + "col").Any())
                            issue.Column = int.Parse(errorElement.Descendants(_namespace + "col").First().Value);
                        if (errorElement.Descendants(_namespace + "message").Any())
                        {
                            issue.Title = errorElement.Descendants(_namespace + "message").First().Value;
                            issue.MessageId = Encoding.UTF8.GetString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(issue.Title)));
                        }

                        issues.Add(issue);
                    }
                }
            }

            return issues;
        }
开发者ID:HippoValidator,项目名称:W3CCssValidationClient,代码行数:30,代码来源:W3CCssValidator.cs

示例10: InitRssItems

        private void InitRssItems(XContainer doc)
        {
            var items = doc.Descendants(@"item");
            foreach (var item in items)
            {
                var title = item.Element("title");
                var date = item.Element("pubDate");
                var link = item.Element("link");

                if (title == null)
                {
                    throw new XmlException("Xml schema has changed: missing '//item/title' node");
                }
                if (date == null)
                {
                    throw new XmlException("Xml schema has changed: missing '//item/pubDate' node");
                }
                if (link == null)
                {
                    throw new XmlException("Xml schema has changed: missing '//item/link' node");
                }

                _rssVm.Items.Add(new RssItemVm(title.Value, ParseTime(date), link.Value));
            }
        }
开发者ID:Dmdv,项目名称:RssCnnReader,代码行数:25,代码来源:XmlFeedReader.cs

示例11: ParseDimensions

        private void ParseDimensions(XContainer xReader)
        {
            IEnumerable<XElement> dimensions = xReader.Descendants("Dimensions").Elements();

            Dictionary<string, int> mapDimensionsDictionary = new Dictionary<string, int>();

            foreach (XElement e in dimensions)
            {
                string elementName = e.Name.ToString();

                int elementValue;

                if (int.TryParse(e.Value, out elementValue))
                    mapDimensionsDictionary[elementName] = elementValue;
                else
                    throw new FormatException("The map file could not be read because its " + elementName.ToLower() + " is not an integer.");
            }

            if (mapDimensionsDictionary.ContainsKey("Width")) mapDimensions.Width = mapDimensionsDictionary["Width"];
            else throw new KeyNotFoundException("The map file could not be read because the map's width was not found.");

            if (mapDimensionsDictionary.ContainsKey("Height")) mapDimensions.Height = mapDimensionsDictionary["Height"];
            else throw new KeyNotFoundException("The map file could not be read because the map's height was not found.");

            if (mapDimensionsDictionary.ContainsKey("TileSize")) mapDimensions.TileSize = mapDimensionsDictionary["TileSize"];
            else throw new KeyNotFoundException("The map file could not be read because the map's tile size was not found.");

            if (mapDimensionsDictionary.ContainsKey("LayerCount")) mapDimensions.LayerCount = mapDimensionsDictionary["LayerCount"];
            else throw new KeyNotFoundException("The map file could not be read because the map's layer count was not found.");
        }
开发者ID:elefantstudio-se,项目名称:tiny-tile-editor,代码行数:30,代码来源:MapReader.cs

示例12: DeserializeAll

        public static IEnumerable<ClientVersion> DeserializeAll(XContainer container)
        {
            if (container == null)
                throw new ArgumentNullException("container");

            return from x in container.Descendants("ClientVersion") select Deserialize(x);
        }
开发者ID:baughj,项目名称:Spark,代码行数:7,代码来源:ClientVersionSerializer.cs

示例13: AccessControlList

        public AccessControlList(XContainer document, IAclSetup ownerObject)
        {
            _ownerObject = ownerObject;

            var element = document.Descendants("Owner").FirstOrDefault();
            if (element != null)
            {
                Owner = new SharpGs.Internal.Owner(null)
                            {
                                ID = element.Descendants("ID").Select(e => e.Value).FirstOrDefault(),
                                DisplayName = element.Descendants("Name").Select(e => e.Value).FirstOrDefault()
                            };
            }
            foreach (var aclEntry in document.Descendants("Entry"))
                _entries.Add(new AclEntry(aclEntry));
        }
开发者ID:acropolium,项目名称:SharpGs,代码行数:16,代码来源:AccessControlList.cs

示例14: GetSubmission

 private static dynamic GetSubmission(XContainer doc)
 {
     return (from element in doc.Descendants(Namespaces.XForms + "submission")
             let resource = element.Attribute("resource")
             where resource != null
             select new {Element = element, TargetUri = resource.Value}).FirstOrDefault();
 }
开发者ID:iansrobinson,项目名称:Restbucks,代码行数:7,代码来源:FormsIntegrityUtility.cs

示例15: ParseParameters

        //todo: this can become private when we remove the template rule
        public static ImmutableList<RuleParameterValues> ParseParameters(XContainer xml)
        {
            var builder = ImmutableList.CreateBuilder<RuleParameterValues>();
            foreach (var rule in xml.Descendants("Rule").Where(e => e.Elements("Parameters").Any()))
            {
                var analyzerId = rule.Elements("Key").Single().Value;

                var parameterValues = rule
                    .Elements("Parameters").Single()
                    .Elements("Parameter")
                    .Select(e => new RuleParameterValue
                    {
                        ParameterKey = e.Elements("Key").Single().Value,
                        ParameterValue = e.Elements("Value").Single().Value
                    });

                var pvs = new RuleParameterValues
                {
                    RuleId = analyzerId
                };
                pvs.ParameterValues.AddRange(parameterValues);

                builder.Add(pvs);
            }

            return builder.ToImmutable();
        }
开发者ID:jakobehn,项目名称:sonarlint-vs,代码行数:28,代码来源:ParameterLoader.cs


注:本文中的System.Xml.Linq.XContainer.Descendants方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。