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 . Linq ;
@@ -138,11 +136,11 @@ public static XElement ToXElement(this ManifestMetadata metadata, XNamespace ns,
138136 return elem ;
139137 }
140138
141- private static XElement GetXElementFromGroupableItemSets < TSet , TItem > (
139+ private static XElement ? GetXElementFromGroupableItemSets < TSet , TItem > (
142140 XNamespace ns ,
143141 IEnumerable < TSet > objectSets ,
144142 Func < TSet , bool > isGroupable ,
145- Func < TSet , string > getGroupIdentifer ,
143+ Func < TSet , string ? > getGroupIdentifer ,
146144 Func < TSet , IEnumerable < TItem > > getItems ,
147145 Func < XNamespace , TItem , XElement > getXElementFromItem ,
148146 string parentName ,
@@ -233,7 +231,7 @@ private static XElement GetXElementFromPackageDependency(XNamespace ns, PackageD
233231 return new XElement ( ns + "dependency" , attributes ) ;
234232 }
235233
236- private static XElement GetXElementFromFrameworkAssemblies ( XNamespace ns , IEnumerable < FrameworkAssemblyReference > references )
234+ private static XElement ? GetXElementFromFrameworkAssemblies ( XNamespace ns , IEnumerable < FrameworkAssemblyReference > references )
237235 {
238236 if ( references == null || ! references . Any ( ) )
239237 {
@@ -250,7 +248,7 @@ private static XElement GetXElementFromFrameworkAssemblies(XNamespace ns, IEnume
250248 null ) ) ) ;
251249 }
252250
253- private static XElement GetXElementFromManifestContentFiles ( XNamespace ns , IEnumerable < ManifestContentFiles > contentFiles )
251+ private static XElement ? GetXElementFromManifestContentFiles ( XNamespace ns , IEnumerable < ManifestContentFiles > contentFiles )
254252 {
255253 if ( contentFiles == null || ! contentFiles . Any ( ) )
256254 {
@@ -263,34 +261,32 @@ private static XElement GetXElementFromManifestContentFiles(XNamespace ns, IEnum
263261
264262 private static XElement GetXElementFromManifestContentFile ( XNamespace ns , ManifestContentFiles file )
265263 {
266- var attributes = new List < XAttribute > ( ) ;
267-
268- attributes . Add ( GetXAttributeFromNameAndValue ( "include" , file . Include ) ) ;
269- attributes . Add ( GetXAttributeFromNameAndValue ( "exclude" , file . Exclude ) ) ;
270- attributes . Add ( GetXAttributeFromNameAndValue ( "buildAction" , file . BuildAction ) ) ;
271- attributes . Add ( GetXAttributeFromNameAndValue ( "copyToOutput" , file . CopyToOutput ) ) ;
272- attributes . Add ( GetXAttributeFromNameAndValue ( "flatten" , file . Flatten ) ) ;
273-
274- attributes = attributes . Where ( xAtt => xAtt != null ) . ToList ( ) ;
275-
276- return new XElement ( ns + Files , attributes ) ;
264+ var attributes = new List < XAttribute ? >
265+ {
266+ GetXAttributeFromNameAndValue ( "include" , file . Include ) ,
267+ GetXAttributeFromNameAndValue ( "exclude" , file . Exclude ) ,
268+ GetXAttributeFromNameAndValue ( "buildAction" , file . BuildAction ) ,
269+ GetXAttributeFromNameAndValue ( "copyToOutput" , file . CopyToOutput ) ,
270+ GetXAttributeFromNameAndValue ( "flatten" , file . Flatten )
271+ } ;
272+
273+ return new XElement ( ns + Files , attributes . Where ( xAtt => xAtt != null ) ) ;
277274 }
278275
279276 private static XElement GetXElementFromLicenseMetadata ( XNamespace ns , LicenseMetadata metadata )
280277 {
281- var attributes = new List < XAttribute > ( ) ;
278+ var attributes = new List < XAttribute ? > ( ) ;
282279
283280 attributes . Add ( GetXAttributeFromNameAndValue ( NuspecUtility . Type , metadata . Type . ToString ( ) . ToLowerInvariant ( ) ) ) ;
284281 if ( ! metadata . Version . Equals ( LicenseMetadata . EmptyVersion ) )
285282 {
286283 attributes . Add ( GetXAttributeFromNameAndValue ( NuspecUtility . Version , metadata . Version ) ) ;
287284 }
288- attributes = attributes . Where ( xAtt => xAtt != null ) . ToList ( ) ;
289285
290- return new XElement ( ns + NuspecUtility . License , metadata . License , attributes ) ;
286+ return new XElement ( ns + NuspecUtility . License , metadata . License , attributes . Where ( xAtt => xAtt != null ) ) ;
291287 }
292288
293- private static XElement GetXElementFromManifestRepository ( XNamespace ns , RepositoryMetadata repository )
289+ private static XElement ? GetXElementFromManifestRepository ( XNamespace ns , RepositoryMetadata repository )
294290 {
295291 var attributeList = new List < XAttribute > ( ) ;
296292 if ( repository != null && ! string . IsNullOrEmpty ( repository . Type ) )
@@ -305,12 +301,12 @@ private static XElement GetXElementFromManifestRepository(XNamespace ns, Reposit
305301
306302 if ( ! string . IsNullOrEmpty ( repository ? . Branch ) )
307303 {
308- attributeList . Add ( new XAttribute ( NuspecUtility . RepositoryBranch , repository . Branch ) ) ;
304+ attributeList . Add ( new XAttribute ( NuspecUtility . RepositoryBranch , repository ! . Branch ! ) ) ;
309305 }
310306
311307 if ( ! string . IsNullOrEmpty ( repository ? . Commit ) )
312308 {
313- attributeList . Add ( new XAttribute ( NuspecUtility . RepositoryCommit , repository . Commit ) ) ;
309+ attributeList . Add ( new XAttribute ( NuspecUtility . RepositoryCommit , repository ! . Commit ! ) ) ;
314310 }
315311
316312 if ( attributeList . Count > 0 )
@@ -335,20 +331,18 @@ private static XElement GetXElementFromManifestPackageTypes(XNamespace ns, IEnum
335331
336332 private static XElement GetXElementFromManifestPackageType ( XNamespace ns , PackageType packageType )
337333 {
338- var attributes = new List < XAttribute > ( ) ;
334+ var attributes = new List < XAttribute ? > ( ) ;
339335
340336 attributes . Add ( GetXAttributeFromNameAndValue ( NuspecUtility . Name , packageType . Name ) ) ;
341337 if ( packageType . Version != PackageType . EmptyVersion )
342338 {
343339 attributes . Add ( GetXAttributeFromNameAndValue ( NuspecUtility . Version , packageType . Version ) ) ;
344340 }
345341
346- attributes = attributes . Where ( xAtt => xAtt != null ) . ToList ( ) ;
347-
348- return new XElement ( ns + NuspecUtility . PackageType , attributes ) ;
342+ return new XElement ( ns + NuspecUtility . PackageType , attributes . Where ( xAtt => xAtt != null ) ) ;
349343 }
350344
351- private static XAttribute GetXAttributeFromNameAndValue ( string name , object value )
345+ private static XAttribute ? GetXAttributeFromNameAndValue ( string name , object ? value )
352346 {
353347 if ( name == null || value == null )
354348 {
@@ -358,7 +352,7 @@ private static XAttribute GetXAttributeFromNameAndValue(string name, object valu
358352 return new XAttribute ( name , value ) ;
359353 }
360354
361- private static void AddElementIfNotNull < T > ( XElement parent , XNamespace ns , string name , T value )
355+ private static void AddElementIfNotNull < T > ( XElement parent , XNamespace ns , string name , T ? value )
362356 where T : class
363357 {
364358 if ( value != null )
@@ -367,7 +361,7 @@ private static void AddElementIfNotNull<T>(XElement parent, XNamespace ns, strin
367361 }
368362 }
369363
370- private static void AddElementIfNotNull < T > ( XElement parent , XNamespace ns , string name , T value , Func < T , object > process )
364+ private static void AddElementIfNotNull < T > ( XElement parent , XNamespace ns , string name , T ? value , Func < T , object > process )
371365 where T : class
372366 {
373367 if ( value != null )
0 commit comments