Skip to content

Commit 3bb1196

Browse files
committed
NuGet.Protocol nullability v2
1 parent 4d0b9dd commit 3bb1196

10 files changed

Lines changed: 121 additions & 131 deletions

src/NuGet.Core/NuGet.Protocol/HttpSourceCacheContext.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
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.Diagnostics;
86

97
namespace NuGet.Protocol.Core.Types
108
{
119
public class HttpSourceCacheContext
1210
{
13-
private HttpSourceCacheContext(string rootTempFolder, TimeSpan maxAge, bool directDownload, SourceCacheContext cacheContext)
11+
private HttpSourceCacheContext(string? rootTempFolder, TimeSpan maxAge, bool directDownload, SourceCacheContext cacheContext)
1412
{
1513
if (maxAge <= TimeSpan.Zero)
1614
{
@@ -40,7 +38,7 @@ private HttpSourceCacheContext(string rootTempFolder, TimeSpan maxAge, bool dire
4038
/// A suggested root folder to drop temporary files under, it will get cleared by the
4139
/// disposal of the <see cref="SourceCacheContext"/> that was used to create this instance.
4240
/// </summary>
43-
public string RootTempFolder { get; }
41+
public string? RootTempFolder { get; }
4442

4543
/// <summary>
4644
/// Inner cache context.

src/NuGet.Core/NuGet.Protocol/NullSourceCacheContext.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#nullable disable
2-
31
namespace NuGet.Protocol.Core.Types
42
{
53
public class NullSourceCacheContext : SourceCacheContext
64
{
7-
private static SourceCacheContext _instance;
5+
private static SourceCacheContext? _instance;
86

97
public static SourceCacheContext Instance
108
{
@@ -28,8 +26,8 @@ public override string GeneratedTempFolder
2826
}
2927
}
3028

31-
public override SourceCacheContext WithRefreshCacheTrue() { return _instance; }
29+
public override SourceCacheContext WithRefreshCacheTrue() { return Instance; }
3230

33-
public override SourceCacheContext Clone() { return _instance; }
31+
public override SourceCacheContext Clone() { return Instance; }
3432
}
3533
}

src/NuGet.Core/NuGet.Protocol/PackageDownloadContext.cs

Lines changed: 6 additions & 8 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 NuGet.Configuration;
86
using NuGet.Packaging.Signing;
@@ -21,7 +19,7 @@ public PackageDownloadContext(SourceCacheContext sourceCacheContext) : this(
2119

2220
public PackageDownloadContext(
2321
SourceCacheContext sourceCacheContext,
24-
string directDownloadDirectory,
22+
string? directDownloadDirectory,
2523
bool directDownload)
2624
{
2725
if (sourceCacheContext == null)
@@ -43,9 +41,9 @@ public PackageDownloadContext(
4341

4442
public PackageDownloadContext(
4543
SourceCacheContext sourceCacheContext,
46-
string directDownloadDirectory,
44+
string? directDownloadDirectory,
4745
bool directDownload,
48-
PackageSourceMapping packageSourceMappingConfiguration) : this(
46+
PackageSourceMapping? packageSourceMappingConfiguration) : this(
4947
sourceCacheContext,
5048
directDownloadDirectory,
5149
directDownload)
@@ -55,11 +53,11 @@ public PackageDownloadContext(
5553

5654
public SourceCacheContext SourceCacheContext { get; }
5755
public bool DirectDownload { get; }
58-
public string DirectDownloadDirectory { get; }
56+
public string? DirectDownloadDirectory { get; }
5957

6058
public Guid ParentId { get; set; }
6159

62-
public ClientPolicyContext ClientPolicyContext { get; set; }
63-
public PackageSourceMapping PackageSourceMapping { get; }
60+
public ClientPolicyContext? ClientPolicyContext { get; set; }
61+
public PackageSourceMapping? PackageSourceMapping { get; }
6462
}
6563
}

src/NuGet.Core/NuGet.Protocol/PublicAPI/net472/PublicAPI.Shipped.txt

Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

src/NuGet.Core/NuGet.Protocol/PublicAPI/net8.0/PublicAPI.Shipped.txt

Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

src/NuGet.Core/NuGet.Protocol/RemoteSourceDependencyInfo.cs

Lines changed: 7 additions & 4 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;
@@ -40,6 +38,11 @@ public RemoteSourceDependencyInfo(
4038
throw new ArgumentNullException(nameof(dependencyGroups));
4139
}
4240

41+
if (contentUri == null)
42+
{
43+
throw new ArgumentNullException(nameof(contentUri));
44+
}
45+
4346
Identity = identity;
4447
Listed = listed;
4548
DependencyGroups = dependencyGroups.ToList();
@@ -66,15 +69,15 @@ public RemoteSourceDependencyInfo(
6669
/// </summary>
6770
public string ContentUri { get; set; }
6871

69-
public bool Equals(RemoteSourceDependencyInfo other)
72+
public bool Equals(RemoteSourceDependencyInfo? other)
7073
{
7174
return other != null &&
7275
Identity.Equals(other.Identity) &&
7376
new HashSet<PackageDependencyGroup>(DependencyGroups).SetEquals(other.DependencyGroups) &&
7477
string.Equals(ContentUri, other.ContentUri, StringComparison.Ordinal);
7578
}
7679

77-
public override bool Equals(object obj) => Equals(obj as PackageDependencyInfo);
80+
public override bool Equals(object? obj) => Equals(obj as RemoteSourceDependencyInfo);
7881

7982
public override int GetHashCode()
8083
{

src/NuGet.Core/NuGet.Protocol/SourceCacheContext.cs

Lines changed: 5 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.Diagnostics;
86
using System.IO;
@@ -19,7 +17,7 @@ public class SourceCacheContext : IDisposable
1917
/// <summary>
2018
/// Path of temp folder if requested by GeneratedTempFolder
2119
/// </summary>
22-
private string _generatedTempFolder = null;
20+
private string? _generatedTempFolder;
2321

2422
/// <summary>
2523
/// Default amount of time to cache version lists.
@@ -121,16 +119,17 @@ public virtual string GeneratedTempFolder
121119
/// </summary>
122120
public virtual SourceCacheContext Clone()
123121
{
124-
return new SourceCacheContext()
122+
var clone = new SourceCacheContext()
125123
{
126124
DirectDownload = DirectDownload,
127125
IgnoreFailedSources = IgnoreFailedSources,
128126
MaxAge = MaxAge,
129127
NoCache = NoCache,
130-
GeneratedTempFolder = _generatedTempFolder,
131128
RefreshMemoryCache = RefreshMemoryCache,
132129
SessionId = SessionId
133130
};
131+
clone._generatedTempFolder = _generatedTempFolder;
132+
return clone;
134133
}
135134

136135
/// <summary>
@@ -161,7 +160,7 @@ protected virtual void Dispose(bool disposing)
161160
{
162161
try
163162
{
164-
Directory.Delete(_generatedTempFolder, recursive: true);
163+
Directory.Delete(currentTempFolder, recursive: true);
165164
}
166165
catch
167166
{

src/NuGet.Core/NuGet.Protocol/SourcePackageDependencyInfo.cs

Lines changed: 10 additions & 12 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.Packaging.Core;
@@ -17,7 +15,7 @@ public SourcePackageDependencyInfo(
1715
NuGetVersion version,
1816
IEnumerable<PackageDependency> dependencies,
1917
bool listed,
20-
SourceRepository source)
18+
SourceRepository? source)
2119
: this(
2220
new PackageIdentity(id, version),
2321
dependencies,
@@ -33,9 +31,9 @@ public SourcePackageDependencyInfo(
3331
NuGetVersion version,
3432
IEnumerable<PackageDependency> dependencies,
3533
bool listed,
36-
SourceRepository source,
37-
Uri downloadUri,
38-
string packageHash)
34+
SourceRepository? source,
35+
Uri? downloadUri,
36+
string? packageHash)
3937
: this(
4038
new PackageIdentity(id, version),
4139
dependencies,
@@ -50,9 +48,9 @@ public SourcePackageDependencyInfo(
5048
PackageIdentity identity,
5149
IEnumerable<PackageDependency> dependencies,
5250
bool listed,
53-
SourceRepository source,
54-
Uri downloadUri,
55-
string packageHash)
51+
SourceRepository? source,
52+
Uri? downloadUri,
53+
string? packageHash)
5654
: base(identity, dependencies)
5755
{
5856
Listed = listed;
@@ -70,18 +68,18 @@ public SourcePackageDependencyInfo(
7068
/// <summary>
7169
/// Source repository the dependency information was retrieved from.
7270
/// </summary>
73-
public SourceRepository Source { get; }
71+
public SourceRepository? Source { get; }
7472

7573
/// <summary>
7674
/// The HTTP, UNC, or local file URI to the package nupkg.
7775
/// </summary>
7876
/// <remarks>Optional</remarks>
79-
public Uri DownloadUri { get; }
77+
public Uri? DownloadUri { get; }
8078

8179
/// <summary>
8280
/// Package hash
8381
/// </summary>
8482
/// <remarks>Optional</remarks>
85-
public string PackageHash { get; }
83+
public string? PackageHash { get; }
8684
}
8785
}

src/NuGet.Core/NuGet.Protocol/UserAgent.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.Net.Http;
86
using NuGet.Packaging;

src/NuGet.Core/NuGet.Protocol/UserAgentStringBuilder.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
#if NETCOREAPP
75
using System;
86
#endif
@@ -22,9 +20,9 @@ public class UserAgentStringBuilder
2220
private const string UserAgentTemplate = "{0}/{1}";
2321

2422
private readonly string _clientName;
25-
private string _vsInfo;
26-
private string _osInfo;
27-
private string _ciInfo;
23+
private string? _vsInfo;
24+
private string? _osInfo;
25+
private string? _ciInfo;
2826

2927
public UserAgentStringBuilder()
3028
: this(DefaultNuGetClientName)
@@ -54,7 +52,7 @@ internal UserAgentStringBuilder(string clientName, IEnvironmentVariableReader en
5452

5553
public string NuGetClientVersion { get; }
5654

57-
public UserAgentStringBuilder WithVisualStudioSKU(string vsInfo)
55+
public UserAgentStringBuilder WithVisualStudioSKU(string? vsInfo)
5856
{
5957
_vsInfo = vsInfo;
6058
return this;

0 commit comments

Comments
 (0)