1+ using AngleSharp . Dom ;
2+ using System ;
3+ using System . Collections . Generic ;
4+ using System . Diagnostics ;
5+ using System . Xml ;
6+ using System . Xml . XPath ;
7+
18namespace AngleSharp . XPath
29{
3- using AngleSharp . Dom ;
4- using System ;
5- using System . Collections . Generic ;
6- using System . Diagnostics ;
7- using System . Xml ;
8- using System . Xml . XPath ;
9-
1010 /// <summary>
1111 /// Hosts the extension methods for XPath parsing.
1212 /// </summary>
1313 public static class Extensions
14- {
14+ {
1515 /// <summary>
1616 /// Creates a new navigator for the given document.
1717 /// </summary>
1818 /// <param name="document">The document to extend.</param>
1919 /// <returns>The navigator for XPath expressions.</returns>
20- public static XPathNavigator CreateNavigator ( this IDocument document )
21- {
20+ public static XPathNavigator CreateNavigator ( this IDocument document )
21+ {
2222 var doc = document ?? throw new ArgumentNullException ( nameof ( document ) ) ;
2323 return new HtmlDocumentNavigator ( doc , doc . DocumentElement ) ;
24- }
25-
26- [ DebuggerStepThrough ]
27- internal static String GetOrAdd ( this XmlNameTable table , String array )
28- {
29- var s = table . Get ( array ) ;
24+ }
3025
31- if ( s == null )
32- {
33- return table . Add ( array ) ;
34- }
35-
36- return s ;
37- }
26+ [ DebuggerStepThrough ]
27+ internal static string GetOrAdd ( this XmlNameTable table , string array )
28+ {
29+ var s = table . Get ( array ) ;
30+ return s ?? table . Add ( array ) ;
31+ }
3832
3933 /// <summary>
4034 /// Selects a single node (or returns null) matching the <see cref="XPath"/> expression.
@@ -43,21 +37,14 @@ internal static String GetOrAdd(this XmlNameTable table, String array)
4337 /// <param name="xpath">The XPath expression.</param>
4438 /// <returns>The node matching <paramref name="xpath"/> query, if any.</returns>
4539 /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
46- public static INode SelectSingleNode ( this IElement element , String xpath )
47- {
40+ public static INode SelectSingleNode ( this IElement element , string xpath )
41+ {
4842 var el = element ?? throw new ArgumentNullException ( nameof ( element ) ) ;
4943 var xp = xpath ?? throw new ArgumentNullException ( nameof ( xpath ) ) ;
50- var nav = new HtmlDocumentNavigator ( el . Owner , el ) ;
51- var it = nav . Select ( xp ) ;
52-
53- if ( it . MoveNext ( ) )
54- {
55- var node = ( HtmlDocumentNavigator ) it . Current ;
56- return node . CurrentNode ;
57- }
58-
59- return null ;
60- }
44+ var nav = new HtmlDocumentNavigator ( el . Owner , el ) ;
45+ var it = nav . SelectSingleNode ( xp ) ;
46+ return ( ( HtmlDocumentNavigator ) it ) ? . CurrentNode ;
47+ }
6148
6249 /// <summary>
6350 /// Selects a list of nodes matching the <see cref="XPath"/> expression.
@@ -66,22 +53,24 @@ public static INode SelectSingleNode(this IElement element, String xpath)
6653 /// <param name="xpath">The XPath expression.</param>
6754 /// <returns>List of nodes matching <paramref name="xpath"/> query.</returns>
6855 /// <exception cref="ArgumentNullException">Throws if <paramref name="element"/> or <paramref name="xpath"/> is <c>null</c></exception>
69- public static List < INode > SelectNodes ( this IElement element , String xpath )
56+ public static List < INode > SelectNodes ( this IElement element , string xpath )
7057 {
7158 var el = element ?? throw new ArgumentNullException ( nameof ( element ) ) ;
7259 var xp = xpath ?? throw new ArgumentNullException ( nameof ( xpath ) ) ;
7360 var nav = new HtmlDocumentNavigator ( el . Owner , el ) ;
74- var it = nav . Select ( xp ) ;
75- var result = new List < INode > ( ) ;
61+ var it = nav . Select ( xp ) ;
62+ var result = new List < INode > ( ) ;
7663
77- while ( it . MoveNext ( ) )
78- {
79- var naviagtor = ( HtmlDocumentNavigator ) it . Current ;
80- var e = naviagtor . CurrentNode ;
81- result . Add ( e ) ;
82- }
64+ while ( it . MoveNext ( ) )
65+ {
66+ // ReSharper disable once IdentifierTypo
67+ var naviagtor = ( HtmlDocumentNavigator ) it . Current ;
68+ // ReSharper disable once PossibleNullReferenceException
69+ var e = naviagtor . CurrentNode ;
70+ result . Add ( e ) ;
71+ }
8372
84- return result ;
85- }
86- }
73+ return result ;
74+ }
75+ }
8776}
0 commit comments