Skip to content

Commit 4c0f54c

Browse files
fix nullable return for .NET8
1 parent 3212019 commit 4c0f54c

File tree

6 files changed

+77
-11
lines changed

6 files changed

+77
-11
lines changed

src/HtmlAgilityPack.Shared/HtmlEntity.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,13 @@ private HtmlEntity()
591591
/// </summary>
592592
/// <param name="text">The source text.</param>
593593
/// <returns>The result text.</returns>
594-
public static string DeEntitize(string text)
594+
public static
595+
#if NET8_0
596+
string?
597+
#else
598+
string
599+
#endif
600+
DeEntitize(string text)
595601
{
596602
if (text == null)
597603
return null;
@@ -770,7 +776,13 @@ public static string Entitize(string text, bool useNames)
770776
/// <param name="useNames">If set to false, the function will not use known entities name. Default is true.</param>
771777
/// <param name="entitizeQuotAmpAndLtGt">If set to true, the [quote], [ampersand], [lower than] and [greather than] characters will be entitized.</param>
772778
/// <returns>The result text</returns>
773-
public static string Entitize(string text, bool useNames, bool entitizeQuotAmpAndLtGt)
779+
public static
780+
#if NET8_0
781+
string?
782+
#else
783+
string
784+
#endif
785+
Entitize(string text, bool useNames, bool entitizeQuotAmpAndLtGt)
774786
// _entityValue.Add("quot", 34); // quotation mark = APL quote, U+0022 ISOnum
775787
// _entityName.Add(34, "quot");
776788
// _entityValue.Add("amp", 38); // ampersand, U+0026 ISOnum

src/HtmlAgilityPack.Shared/HtmlNode.Xpath.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ public XPathNavigator CreateRootNavigator()
3737
/// </summary>
3838
/// <param name="xpath">The XPath expression.</param>
3939
/// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns>
40-
public HtmlNodeCollection SelectNodes(string xpath)
40+
public
41+
#if NET8_0
42+
HtmlNodeCollection?
43+
#else
44+
HtmlNodeCollection
45+
#endif
46+
SelectNodes(string xpath)
4147
{
4248
HtmlNodeCollection list = new HtmlNodeCollection(null);
4349

@@ -62,7 +68,13 @@ public HtmlNodeCollection SelectNodes(string xpath)
6268
/// </summary>
6369
/// <param name="xpath">The XPath expression.</param>
6470
/// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns>
65-
public HtmlNodeCollection SelectNodes(XPathExpression xpath)
71+
public
72+
#if NET8_0
73+
HtmlNodeCollection?
74+
#else
75+
HtmlNodeCollection
76+
#endif
77+
SelectNodes(XPathExpression xpath)
6678
{
6779
HtmlNodeCollection list = new HtmlNodeCollection(null);
6880

@@ -87,7 +99,13 @@ public HtmlNodeCollection SelectNodes(XPathExpression xpath)
8799
/// </summary>
88100
/// <param name="xpath">The XPath expression. May not be null.</param>
89101
/// <returns>The first <see cref="HtmlNode"/> that matches the XPath query or a null reference if no matching node was found.</returns>
90-
public HtmlNode SelectSingleNode(string xpath)
102+
public
103+
#if NET8_0
104+
HtmlNode?
105+
#else
106+
HtmlNode
107+
#endif
108+
SelectSingleNode(string xpath)
91109
{
92110
if (xpath == null)
93111
{
@@ -110,7 +128,13 @@ public HtmlNode SelectSingleNode(string xpath)
110128
/// </summary>
111129
/// <param name="xpath">The XPath expression.</param>
112130
/// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns>
113-
public HtmlNode SelectSingleNode(XPathExpression xpath)
131+
public
132+
#if NET8_0
133+
HtmlNode?
134+
#else
135+
HtmlNode
136+
#endif
137+
SelectSingleNode(XPathExpression xpath)
114138
{
115139
if (xpath == null)
116140
{

src/HtmlAgilityPack.Shared/HtmlNode.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,13 @@ public IEnumerable<HtmlNode> DescendantsAndSelf(string name)
13071307
/// </summary>
13081308
/// <param name="name"></param>
13091309
/// <returns></returns>
1310-
public HtmlNode Element(string name)
1310+
public
1311+
#if NET8_0
1312+
HtmlNode?
1313+
#else
1314+
HtmlNode
1315+
#endif
1316+
Element(string name)
13111317
{
13121318
foreach (HtmlNode node in ChildNodes)
13131319
if (node.Name == name)

src/HtmlAgilityPack.Shared/HtmlNodeCollection.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ public int this[HtmlNode node]
6868
/// </summary>
6969
/// <param name="nodeName"></param>
7070
/// <returns></returns>
71-
public HtmlNode this[string nodeName]
71+
public
72+
#if NET8_0
73+
HtmlNode?
74+
#else
75+
HtmlNode
76+
#endif
77+
this[string nodeName]
7278
{
7379
get
7480
{
@@ -296,7 +302,13 @@ public void RemoveAt(int index)
296302
/// <param name="items"></param>
297303
/// <param name="name"></param>
298304
/// <returns></returns>
299-
public static HtmlNode FindFirst(HtmlNodeCollection items, string name)
305+
public static
306+
#if NET8_0
307+
HtmlNode?
308+
#else
309+
HtmlNode
310+
#endif
311+
FindFirst(HtmlNodeCollection items, string name)
300312
{
301313
foreach (HtmlNode node in items)
302314
{

src/HtmlAgilityPack.Shared/HtmlNodeNavigator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,13 @@ public override XPathNavigator Clone()
528528
/// <param name="localName">The local name of the HTML attribute.</param>
529529
/// <param name="namespaceURI">The namespace URI of the attribute. Unsupported with the HtmlNavigator implementation.</param>
530530
/// <returns>The value of the specified HTML attribute. String.Empty or null if a matching attribute is not found or if the navigator is not positioned on an element node.</returns>
531-
public override string GetAttribute(string localName, string namespaceURI)
531+
public override
532+
#if NET8_0
533+
string?
534+
#else
535+
string
536+
#endif
537+
GetAttribute(string localName, string namespaceURI)
532538
{
533539
#if TRACE_NAVIGATOR
534540
InternalTrace("localName=" + localName + ", namespaceURI=" + namespaceURI);

src/HtmlAgilityPack.Shared/Utilities.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ namespace HtmlAgilityPack
1313
{
1414
internal static class Utilities
1515
{
16-
public static TValue GetDictionaryValueOrDefault<TKey, TValue>(Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue)) where TKey : class
16+
public static
17+
#if NET8_0
18+
TValue?
19+
#else
20+
TValue
21+
#endif
22+
GetDictionaryValueOrDefault<TKey, TValue>(Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue)) where TKey : class
1723
{
1824
TValue value;
1925
if (!dict.TryGetValue(key, out value))

0 commit comments

Comments
 (0)