Skip to content

Commit 20cc766

Browse files
committed
cleanup
1 parent 7b498ad commit 20cc766

14 files changed

Lines changed: 114 additions & 131 deletions

src/NuGet.Core/NuGet.Commands/RestoreCommand/DependencyGraphResolver.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,10 @@ .. chosenResolvedItem.Suppressions
12921292
// The list of suppressions should be an aggregate of all parent item's suppressions so add the parent suppressions to the list, otherwise just use the current item's suppressions
12931293
if (suppressions != null)
12941294
{
1295-
suppressions.AddRange(currentDependencyGraphItem.Suppressions);
1295+
if (currentDependencyGraphItem.Suppressions != null)
1296+
{
1297+
suppressions.AddRange(currentDependencyGraphItem.Suppressions);
1298+
}
12961299
}
12971300
else
12981301
{

src/NuGet.Core/NuGet.Packaging/NuspecReader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public RepositoryMetadata GetRepositoryMetadata()
482482
{
483483
try
484484
{
485-
var expression = NuGetLicenseExpression.Parse(license);
485+
var expression = NuGetLicenseExpression.Parse(license!);
486486

487487
var invalidLicenseIdentifiers = GetNonStandardLicenseIdentifiers(expression);
488488
if (invalidLicenseIdentifiers != null)
@@ -502,7 +502,7 @@ public RepositoryMetadata GetRepositoryMetadata()
502502
errors.Add(string.Format(CultureInfo.CurrentCulture, Strings.NuGetLicenseExpression_UnlicensedPackageWarning));
503503
}
504504

505-
return new LicenseMetadata(type: licenseType, license: license, expression: expression, warningsAndErrors: errors, version: version);
505+
return new LicenseMetadata(type: licenseType, license: license!, expression: expression, warningsAndErrors: errors, version: version);
506506
}
507507
catch (NuGetLicenseExpressionParsingException e)
508508
{
@@ -512,7 +512,7 @@ public RepositoryMetadata GetRepositoryMetadata()
512512
}
513513
errors.Add(e.Message);
514514
}
515-
return new LicenseMetadata(type: licenseType, license: license, expression: null, warningsAndErrors: errors, version: version);
515+
return new LicenseMetadata(type: licenseType, license: license!, expression: null, warningsAndErrors: errors, version: version);
516516
}
517517
else
518518
{
@@ -528,11 +528,11 @@ public RepositoryMetadata GetRepositoryMetadata()
528528
version,
529529
LicenseMetadata.CurrentVersion));
530530

531-
return new LicenseMetadata(type: licenseType, license: license, expression: null, warningsAndErrors: errors, version: version);
531+
return new LicenseMetadata(type: licenseType, license: license!, expression: null, warningsAndErrors: errors, version: version);
532532
}
533533
}
534534
}
535-
return new LicenseMetadata(type: licenseType, license: license, expression: null, warningsAndErrors: errors, version: version);
535+
return new LicenseMetadata(type: licenseType, license: license!, expression: null, warningsAndErrors: errors, version: version);
536536
}
537537
}
538538
return null;

src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/FrameworkAssemblyReference.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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-
64
using System;
75
using System.Collections.Generic;
86
using NuGet.Frameworks;
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
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-
64
namespace NuGet.Packaging
75
{
86
public class ManifestContentFiles
97
{
10-
public string Include { get; set; }
8+
public required string Include { get; set; }
119

12-
public string Exclude { get; set; }
10+
public string? Exclude { get; set; }
1311

14-
public string BuildAction { get; set; }
12+
public string? BuildAction { get; set; }
1513

16-
public string CopyToOutput { get; set; }
14+
public string? CopyToOutput { get; set; }
1715

18-
public string Flatten { get; set; }
16+
public string? Flatten { get; set; }
1917
}
2018
}

src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/ManifestFile.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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-
64
using System;
75
using System.Collections.Generic;
86
using System.Globalization;
@@ -22,40 +20,40 @@ public class ManifestFile
2220
internal static readonly char[] ReferenceFileInvalidCharacters = _invalidSourceCharacters.Concat(new[] { ':', '*', '?', '\\', '/' }).ToArray();
2321
private static readonly char[] _invalidTargetChars = ReferenceFileInvalidCharacters.Except(new[] { '\\', '/' }).ToArray();
2422

25-
private string _target;
26-
public string Source { get; set; }
23+
private string? _target;
24+
public string? Source { get; set; }
2725

28-
public string Target
26+
public string? Target
2927
{
3028
get
3129
{
3230
return _target;
3331
}
3432
set
3533
{
36-
_target = string.IsNullOrEmpty(value) ? value : PathUtility.GetPathWithDirectorySeparator(value);
34+
_target = string.IsNullOrEmpty(value) ? value : PathUtility.GetPathWithDirectorySeparator(value!);
3735
}
3836
}
3937

40-
public string Exclude { get; set; }
38+
public string? Exclude { get; set; }
4139

4240
public IEnumerable<string> Validate()
4341
{
4442
if (String.IsNullOrEmpty(Source))
4543
{
4644
yield return String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_RequiredMetadataMissing, "Source");
4745
}
48-
else if (Source.IndexOfAny(_invalidSourceCharacters) != -1)
46+
else if (Source!.IndexOfAny(_invalidSourceCharacters) != -1)
4947
{
5048
yield return String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_SourceContainsInvalidCharacters, Source);
5149
}
5250

53-
if (!String.IsNullOrEmpty(Target) && Target.IndexOfAny(_invalidTargetChars) != -1)
51+
if (!String.IsNullOrEmpty(Target) && Target!.IndexOfAny(_invalidTargetChars) != -1)
5452
{
5553
yield return String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_TargetContainsInvalidCharacters, Target);
5654
}
5755

58-
if (!String.IsNullOrEmpty(Exclude) && Exclude.IndexOfAny(_invalidSourceCharacters) != -1)
56+
if (!String.IsNullOrEmpty(Exclude) && Exclude!.IndexOfAny(_invalidSourceCharacters) != -1)
5957
{
6058
yield return String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_ExcludeContainsInvalidCharacters, Exclude);
6159
}

src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PackageReferenceSet.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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-
64
using System;
75
using System.Collections.Generic;
86
using System.Globalization;
@@ -19,7 +17,7 @@ public class PackageReferenceSet
1917
/// </summary>
2018
/// <param name="references">IEnumerable set of string references</param>
2119
public PackageReferenceSet(IEnumerable<string> references)
22-
: this((NuGetFramework)null, references)
20+
: this((NuGetFramework?)null, references)
2321
{
2422
}
2523

@@ -28,7 +26,7 @@ public PackageReferenceSet(IEnumerable<string> references)
2826
/// </summary>
2927
/// <param name="targetFramework">The target framework to use, pass Any for AnyFramework. Does not allow null.</param>
3028
/// <param name="references">IEnumerable set of string references</param>
31-
public PackageReferenceSet(string targetFramework, IEnumerable<string> references)
29+
public PackageReferenceSet(string? targetFramework, IEnumerable<string> references)
3230
: this(targetFramework != null ? NuGetFramework.Parse(targetFramework) : null, references)
3331
{
3432
}
@@ -38,7 +36,7 @@ public PackageReferenceSet(string targetFramework, IEnumerable<string> reference
3836
/// </summary>
3937
/// <param name="targetFramework">The target framework to use.</param>
4038
/// <param name="references">IEnumerable set of string references</param>
41-
public PackageReferenceSet(NuGetFramework targetFramework, IEnumerable<string> references)
39+
public PackageReferenceSet(NuGetFramework? targetFramework, IEnumerable<string> references)
4240
{
4341
if (references == null)
4442
{
@@ -51,7 +49,7 @@ public PackageReferenceSet(NuGetFramework targetFramework, IEnumerable<string> r
5149

5250
public IReadOnlyCollection<string> References { get; }
5351

54-
public NuGetFramework TargetFramework { get; }
52+
public NuGetFramework? TargetFramework { get; }
5553

5654
public IEnumerable<string> Validate()
5755
{

src/NuGet.Core/NuGet.Packaging/PackageCreation/Extensions/CollectionExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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-
64
using System.Collections.Generic;
75

86
namespace NuGet.Packaging

src/NuGet.Core/NuGet.Packaging/PackageCreation/Extensions/FrameworksExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
#nullable disable
5-
64
using System;
75
using System.Runtime.Versioning;
86
using NuGet.Frameworks;

src/NuGet.Core/NuGet.Packaging/PackageCreation/Extensions/StringExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
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-
64
namespace NuGet.Packaging
75
{
86
internal static class StringExtensions
97
{
10-
public static string SafeTrim(this string value)
8+
public static string? SafeTrim(this string? value)
119
{
1210
return value == null ? null : value.Trim();
1311
}

src/NuGet.Core/NuGet.Packaging/PackageCreation/Extensions/XElementExtensions.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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-
64
using System;
75
using System.Collections.Generic;
86
using System.Linq;
@@ -13,16 +11,16 @@ namespace NuGet.Packaging
1311
{
1412
public static class XElementExtensions
1513
{
16-
public static string GetOptionalAttributeValue(this XElement element, string localName, string namespaceName = null)
14+
public static string? GetOptionalAttributeValue(this XElement element, string localName, string? namespaceName = null)
1715
{
18-
XAttribute attr;
16+
XAttribute? attr;
1917
if (String.IsNullOrEmpty(namespaceName))
2018
{
2119
attr = element.Attribute(localName);
2220
}
2321
else
2422
{
25-
attr = element.Attribute(XName.Get(localName, namespaceName));
23+
attr = element.Attribute(XName.Get(localName, namespaceName!));
2624
}
2725
return attr != null ? attr.Value : null;
2826
}
@@ -32,7 +30,7 @@ public static IEnumerable<XElement> ElementsNoNamespace(this XContainer containe
3230
return container.Elements().Where(e => e.Name.LocalName == localName);
3331
}
3432

35-
public static XElement Except(this XElement source, XElement target)
33+
public static XElement Except(this XElement source, XElement? target)
3634
{
3735
if (target == null)
3836
{
@@ -82,7 +80,7 @@ where AttributeEquals(e, target.Attribute(e.Name))
8280
return source;
8381
}
8482

85-
private static XElement FindElement(XElement source, XElement targetChild)
83+
private static XElement? FindElement(XElement source, XElement targetChild)
8684
{
8785
// Get all of the elements in the source that match this name
8886
var sourceElements = source.Elements(targetChild.Name).ToList();
@@ -132,7 +130,7 @@ private static bool HasConflict(XElement source, XElement target)
132130
// Loop over all the other attributes and see if there are
133131
foreach (var targetAttr in target.Attributes())
134132
{
135-
string sourceValue;
133+
string? sourceValue;
136134
// if any of the attributes are in the source (names match) but the value doesn't match then we've found a conflict
137135
if (sourceAttr.TryGetValue(targetAttr.Name, out sourceValue)
138136
&& sourceValue != targetAttr.Value)
@@ -143,7 +141,7 @@ private static bool HasConflict(XElement source, XElement target)
143141
return false;
144142
}
145143

146-
private static bool AttributeEquals(XAttribute source, XAttribute target)
144+
private static bool AttributeEquals(XAttribute? source, XAttribute? target)
147145
{
148146
if (source == null
149147
&& target == null)

0 commit comments

Comments
 (0)