11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
4- #nullable disable
5-
64using System ;
75using System . Collections . Generic ;
86using System . Globalization ;
@@ -20,8 +18,8 @@ namespace NuGet.Packaging.Core
2018 public abstract class NuspecCoreReaderBase : INuspecCoreReader
2119 {
2220 private readonly XDocument _xml ;
23- private XElement _metadataNode ;
24- private Dictionary < string , string > _metadataValues ;
21+ private XElement ? _metadataNode ;
22+ private Dictionary < string , string > ? _metadataValues ;
2523
2624 protected const string Metadata = "metadata" ;
2725 protected const string Id = "id" ;
@@ -79,25 +77,29 @@ public NuspecCoreReaderBase(XDocument xml)
7977 /// <summary>
8078 /// Id of the package
8179 /// </summary>
80+ /// <remarks>NU_NULL_INC :This method is annotated as not nullable intentionally.
81+ /// The null return is possible only with malformed nuspecs and practically illegal in cases dealing with an actual package.</remarks>
8282 public virtual string GetId ( )
8383 {
8484 var node = MetadataNode . Elements ( XName . Get ( Id , MetadataNode . GetDefaultNamespace ( ) . NamespaceName ) ) . FirstOrDefault ( ) ;
85- return node == null ? null : node . Value ;
85+ return node == null ? null ! : node . Value ;
8686 }
8787
8888 /// <summary>
8989 /// Version of the package
9090 /// </summary>
91+ /// <remarks>NU_NULL_INC :This method is annotated as not nullable intentionally.
92+ /// The null return is possible only with malformed nuspecs and practically illegal in cases dealing with an actual package.</remarks>
9193 public virtual NuGetVersion GetVersion ( )
9294 {
9395 var node = MetadataNode . Elements ( XName . Get ( Version , MetadataNode . GetDefaultNamespace ( ) . NamespaceName ) ) . FirstOrDefault ( ) ;
94- return node == null ? null : NuGetVersion . Parse ( node . Value ) ;
96+ return node == null ? null ! : NuGetVersion . Parse ( node . Value ) ;
9597 }
9698
9799 /// <summary>
98100 /// The minimum client version this package supports.
99101 /// </summary>
100- public virtual NuGetVersion GetMinClientVersion ( )
102+ public virtual NuGetVersion ? GetMinClientVersion ( )
101103 {
102104 var node = MetadataNode . Attribute ( XName . Get ( MinClientVersion ) ) ;
103105 return node == null ? null : NuGetVersion . Parse ( node . Value ) ;
@@ -144,7 +146,7 @@ public virtual IEnumerable<KeyValuePair<string, string>> GetMetadata()
144146 /// </summary>
145147 public virtual string GetMetadataValue ( string name )
146148 {
147- string metadataValue ;
149+ string ? metadataValue ;
148150 MetadataValues . TryGetValue ( name , out metadataValue ) ;
149151 return metadataValue ?? string . Empty ;
150152 }
@@ -183,7 +185,7 @@ protected XElement MetadataNode
183185 if ( _metadataNode == null )
184186 {
185187 // find the metadata node regardless of the NS, some legacy packages have the NS here instead of on package
186- _metadataNode = _xml . Root . Elements ( ) . FirstOrDefault ( e => StringComparer . Ordinal . Equals ( e . Name . LocalName , Metadata ) ) ;
188+ _metadataNode = _xml . Root ! . Elements ( ) . FirstOrDefault ( e => StringComparer . Ordinal . Equals ( e . Name . LocalName , Metadata ) ) ;
187189
188190 if ( _metadataNode == null )
189191 {
0 commit comments