Skip to content

Commit c0c368a

Browse files
authored
Enabling nullability in NuGet.Packaging - Phase 2, declare some interfaces (#7178)
1 parent a4675d8 commit c0c368a

28 files changed

Lines changed: 357 additions & 394 deletions

src/NuGet.Core/NuGet.Packaging/ContentModel/ContentItemGroup.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
using System.Diagnostics;
86

src/NuGet.Core/NuGet.Packaging/Core/Fingerprints.cs

Lines changed: 1 addition & 3 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

@@ -18,7 +16,7 @@ public Fingerprints(IDictionary<string, string> fingerPrints)
1816
}
1917

2018
// Get fingerprint from hash algorithm oid.
21-
public string this[string key]
19+
public string? this[string key]
2220
{
2321
get
2422
{

src/NuGet.Core/NuGet.Packaging/Core/FrameworkNameValidatorUtility.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System;
42
using System.IO;
53
using NuGet.Frameworks;
@@ -16,7 +14,7 @@ internal static bool IsValidFrameworkName(NuGetFramework framework)
1614

1715
internal static bool IsValidFrameworkName(string path)
1816
{
19-
NuGetFramework fx;
17+
NuGetFramework? fx;
2018
try
2119
{
2220
string effectivePath;

src/NuGet.Core/NuGet.Packaging/Core/IAsyncPackageCoreReader.cs

Lines changed: 1 addition & 3 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.IO;
@@ -37,7 +35,7 @@ public interface IAsyncPackageCoreReader : IDisposable
3735
/// The task result (<see cref="Task{TResult}.Result" />) returns a <see cref="NuGetVersion" />.</returns>
3836
/// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" />
3937
/// is cancelled.</exception>
40-
Task<NuGetVersion> GetMinClientVersionAsync(CancellationToken cancellationToken);
38+
Task<NuGetVersion?> GetMinClientVersionAsync(CancellationToken cancellationToken);
4139

4240
/// <summary>
4341
/// Asynchronously gets zero or more package types from the .nuspec.

src/NuGet.Core/NuGet.Packaging/Core/IPackageCoreReader.cs

Lines changed: 1 addition & 3 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.IO;
@@ -28,7 +26,7 @@ public interface IPackageCoreReader : IDisposable
2826
/// Gets the minimum client version needed to consume the package.
2927
/// </summary>
3028
/// <returns>A NuGet version.</returns>
31-
NuGetVersion GetMinClientVersion();
29+
NuGetVersion? GetMinClientVersion();
3230

3331
/// <summary>
3432
/// Gets zero or more package types from the .nuspec.

src/NuGet.Core/NuGet.Packaging/Core/IRepositoryCertificateInfo.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

86
namespace NuGet.Packaging.Core

src/NuGet.Core/NuGet.Packaging/Core/NuspecUtility.cs

Lines changed: 13 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;
@@ -83,7 +81,7 @@ public static IReadOnlyList<PackageType> GetPackageTypes(XElement metadataNode,
8381

8482
// Get the optional package type version.
8583
var versionAttribute = node.Attribute(XName.Get(Version));
86-
Version version;
84+
Version? version;
8785

8886
if (versionAttribute != null)
8987
{
@@ -122,7 +120,12 @@ public static bool IsServiceable(XElement metadataNode)
122120
return false;
123121
}
124122

125-
var value = element.Value ?? element.Value.Trim();
123+
if (element.Value == null)
124+
{
125+
return false;
126+
}
127+
128+
var value = element.Value.Trim();
126129
return System.Xml.XmlConvert.ToBoolean(value);
127130
}
128131

@@ -143,9 +146,9 @@ internal static IEnumerable<FrameworkReferenceGroup> GetFrameworkReferenceGroups
143146
if (useMetadataNamespace)
144147
{
145148
var frameworkReferencesNode = metadataNode
146-
.Elements(XName.Get(FrameworkReferences, ns));
149+
.Elements(XName.Get(FrameworkReferences, ns!));
147150
frameworkReferenceGroups = frameworkReferencesNode
148-
.Elements(XName.Get(Group, ns));
151+
.Elements(XName.Get(Group, ns!));
149152
}
150153
else
151154
{
@@ -159,10 +162,10 @@ internal static IEnumerable<FrameworkReferenceGroup> GetFrameworkReferenceGroups
159162
var groupFramework = GetAttributeValue(frameworkRefGroup, TargetFramework);
160163

161164
var frameworkReferences = useMetadataNamespace ?
162-
frameworkRefGroup.Elements(XName.Get(FrameworkReference, ns)) :
165+
frameworkRefGroup.Elements(XName.Get(FrameworkReference, ns!)) :
163166
frameworkRefGroup.Elements().Where(x => x.Name.LocalName == FrameworkReference);
164167

165-
var framework = NuGetFramework.Parse(groupFramework, frameworkProvider);
168+
var framework = NuGetFramework.Parse(groupFramework!, frameworkProvider);
166169
var frameworkRefs = GetFrameworkReferences(frameworkReferences);
167170

168171
yield return new FrameworkReferenceGroup(framework, frameworkRefs.Select(e => new FrameworkReference(e)));
@@ -171,10 +174,10 @@ internal static IEnumerable<FrameworkReferenceGroup> GetFrameworkReferenceGroups
171174

172175
private static IEnumerable<string> GetFrameworkReferences(IEnumerable<XElement> nodes)
173176
{
174-
return new HashSet<string>(nodes.Select(e => GetAttributeValue(e, Name)), ComparisonUtility.FrameworkReferenceNameComparer);
177+
return new HashSet<string>(nodes.Select(e => GetAttributeValue(e, Name)!), ComparisonUtility.FrameworkReferenceNameComparer);
175178
}
176179

177-
private static string GetAttributeValue(XElement element, string attributeName)
180+
private static string? GetAttributeValue(XElement element, string attributeName)
178181
{
179182
var attribute = element.Attribute(XName.Get(attributeName));
180183
return attribute == null ? null : attribute.Value;

src/NuGet.Core/NuGet.Packaging/Definitions/IAsyncPackageContentReader.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
using System.Threading;
86
using System.Threading.Tasks;

src/NuGet.Core/NuGet.Packaging/Definitions/INuspecReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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-
4+
using System;
65
using System.Collections.Generic;
76
using NuGet.Packaging.Core;
87

@@ -11,6 +10,7 @@ namespace NuGet.Packaging
1110
/// <summary>
1211
/// A development package nuspec reader
1312
/// </summary>
13+
[Obsolete("This interface is unused and does not contain any implementations. It will be removed in a future release.")]
1414
public interface INuspecReader : INuspecCoreReader
1515
{
1616
IEnumerable<PackageDependencyGroup> GetDependencyGroups();

src/NuGet.Core/NuGet.Packaging/Definitions/IPackageContentReader.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

0 commit comments

Comments
 (0)