Skip to content

Commit 9a3bec4

Browse files
committed
cleanup
1 parent 79be6ed commit 9a3bec4

9 files changed

Lines changed: 452 additions & 505 deletions

File tree

src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/Manifest.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.Globalization;
@@ -30,7 +28,7 @@ public Manifest(ManifestMetadata metadata)
3028
{
3129
}
3230

33-
public Manifest(ManifestMetadata metadata, ICollection<ManifestFile> files)
31+
public Manifest(ManifestMetadata metadata, ICollection<ManifestFile>? files)
3432
{
3533
if (metadata == null)
3634
{
@@ -105,7 +103,7 @@ public void Save(Stream stream, int minimumManifestVersion, bool generateBackwar
105103
Files.Any() ?
106104
new XElement(schemaNamespace + "files",
107105
Files.Select(file => new XElement(schemaNamespace + "file",
108-
new XAttribute("src", file.Source),
106+
new XAttribute("src", file.Source!),
109107
file.Target != null ? new XAttribute("target", file.Target) : null,
110108
file.Exclude != null ? new XAttribute("exclude", file.Exclude) : null))) : null)).Save(stream);
111109
}
@@ -115,12 +113,12 @@ public static Manifest ReadFrom(Stream stream, bool validateSchema)
115113
return ReadFrom(stream, null, validateSchema);
116114
}
117115

118-
public static Manifest ReadFrom(Stream stream, Func<string, string> propertyProvider, bool validateSchema)
116+
public static Manifest ReadFrom(Stream stream, Func<string, string>? propertyProvider, bool validateSchema)
119117
{
120118
return ReadFrom(stream, propertyProvider, validateSchema, overrideVersion: null);
121119
}
122120

123-
public static Manifest ReadFrom(Stream stream, Func<string, string> propertyProvider, bool validateSchema, NuGetVersion overrideVersion)
121+
public static Manifest ReadFrom(Stream stream, Func<string, string>? propertyProvider, bool validateSchema, NuGetVersion? overrideVersion)
124122
{
125123
XDocument document;
126124
if (propertyProvider == null)
@@ -166,7 +164,7 @@ public static Manifest ReadFrom(Stream stream, Func<string, string> propertyProv
166164
private static string GetSchemaNamespace(XDocument document)
167165
{
168166
string schemaNamespace = ManifestSchemaUtility.SchemaVersionV1;
169-
var rootNameSpace = document.Root.Name.Namespace;
167+
var rootNameSpace = document.Root!.Name.Namespace;
170168
if (rootNameSpace != null && !String.IsNullOrEmpty(rootNameSpace.NamespaceName))
171169
{
172170
schemaNamespace = rootNameSpace.NamespaceName;
@@ -227,7 +225,7 @@ private static void CheckSchemaVersion(XDocument document)
227225
}
228226

229227
// Get the package id from the metadata node
230-
string packageId = GetPackageId(metadata);
228+
string? packageId = GetPackageId(metadata);
231229

232230
// If the schema of the document doesn't match any of our known schemas
233231
if (!ManifestSchemaUtility.IsKnownSchema(document.Root.Name.Namespace.NamespaceName))
@@ -243,7 +241,7 @@ private static void CheckSchemaVersion(XDocument document)
243241
}
244242

245243
#if !IS_CORECLR
246-
private static string GetPackageId(XElement metadataElement)
244+
private static string? GetPackageId(XElement metadataElement)
247245
{
248246
XName idName = XName.Get("id", metadataElement.Document.Root.Name.NamespaceName);
249247
XElement element = metadataElement.Element(idName);

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

Lines changed: 31 additions & 33 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,14 +17,14 @@ namespace NuGet.Packaging
1917
/// </summary>
2018
public class ManifestMetadata : IPackageMetadata
2119
{
22-
private string _minClientVersionString;
20+
private string? _minClientVersionString;
2321

2422
private IEnumerable<string> _authors = Enumerable.Empty<string>();
2523
private IEnumerable<string> _owners = Enumerable.Empty<string>();
2624

27-
private string _iconUrl;
28-
private string _licenseUrl;
29-
private string _projectUrl;
25+
private string? _iconUrl;
26+
private string? _licenseUrl;
27+
private string? _projectUrl;
3028

3129
public ManifestMetadata()
3230
{
@@ -42,7 +40,7 @@ public ManifestMetadata(IPackageMetadata copy)
4240
Title = copy.Title?.Trim();
4341
Authors = copy.Authors;
4442
Owners = copy.Owners;
45-
Tags = string.IsNullOrEmpty(copy.Tags) ? null : copy.Tags.Trim();
43+
Tags = string.IsNullOrEmpty(copy.Tags) ? null : copy.Tags!.Trim();
4644
Serviceable = copy.Serviceable;
4745
_licenseUrl = copy.LicenseUrl?.OriginalString;
4846
_projectUrl = copy.ProjectUrl?.OriginalString;
@@ -68,12 +66,12 @@ public ManifestMetadata(IPackageMetadata copy)
6866
Readme = copy.Readme;
6967
}
7068

71-
public string MinClientVersionString
69+
public string? MinClientVersionString
7270
{
7371
get { return _minClientVersionString; }
7472
set
7573
{
76-
Version version = null;
74+
Version? version = null;
7775
if (!String.IsNullOrEmpty(value) && !System.Version.TryParse(value, out version))
7876
{
7977
throw new InvalidDataException(NuGetResources.Manifest_InvalidMinClientVersion);
@@ -84,13 +82,13 @@ public string MinClientVersionString
8482
}
8583
}
8684

87-
public Version MinClientVersion { get; private set; }
85+
public Version? MinClientVersion { get; private set; }
8886

89-
public string Id { get; set; }
87+
public string? Id { get; set; }
9088

91-
public NuGetVersion Version { get; set; }
89+
public NuGetVersion? Version { get; set; }
9290

93-
public string Title { get; set; }
91+
public string? Title { get; set; }
9492

9593
public IEnumerable<string> Authors
9694
{
@@ -106,12 +104,12 @@ public IEnumerable<string> Owners
106104

107105
// The (Icon/License/Project)Url properties have backing strings as we need to be able to differentiate
108106
// between the property not being set (valid) and set to an empty value (invalid).
109-
public void SetIconUrl(string iconUrl)
107+
public void SetIconUrl(string? iconUrl)
110108
{
111109
_iconUrl = iconUrl;
112110
}
113111

114-
public Uri IconUrl
112+
public Uri? IconUrl
115113
{
116114
get
117115
{
@@ -124,14 +122,14 @@ public Uri IconUrl
124122
}
125123
}
126124

127-
public string Icon { get; set; }
125+
public string? Icon { get; set; }
128126

129-
public void SetLicenseUrl(string licenseUrl)
127+
public void SetLicenseUrl(string? licenseUrl)
130128
{
131129
_licenseUrl = licenseUrl;
132130
}
133131

134-
public Uri LicenseUrl
132+
public Uri? LicenseUrl
135133
{
136134
get
137135
{
@@ -144,12 +142,12 @@ public Uri LicenseUrl
144142
}
145143
}
146144

147-
public void SetProjectUrl(string projectUrl)
145+
public void SetProjectUrl(string? projectUrl)
148146
{
149147
_projectUrl = projectUrl;
150148
}
151149

152-
public Uri ProjectUrl
150+
public Uri? ProjectUrl
153151
{
154152
get
155153
{
@@ -168,23 +166,23 @@ public Uri ProjectUrl
168166

169167
public bool DevelopmentDependency { get; set; }
170168

171-
public string Description { get; set; }
169+
public string? Description { get; set; }
172170

173-
public string Summary { get; set; }
171+
public string? Summary { get; set; }
174172

175-
public string ReleaseNotes { get; set; }
173+
public string? ReleaseNotes { get; set; }
176174

177-
public string Copyright { get; set; }
175+
public string? Copyright { get; set; }
178176

179-
public string Language { get; set; }
177+
public string? Language { get; set; }
180178

181-
public string Tags { get; set; }
179+
public string? Tags { get; set; }
182180

183-
public string Readme { get; set; }
181+
public string? Readme { get; set; }
184182

185183
public bool Serviceable { get; set; }
186184

187-
public RepositoryMetadata Repository { get; set; }
185+
public RepositoryMetadata? Repository { get; set; }
188186

189187
private IEnumerable<PackageDependencyGroup> _dependencyGroups = [];
190188
public IEnumerable<PackageDependencyGroup> DependencyGroups
@@ -222,7 +220,7 @@ private static IEnumerable<PackageReferenceSet> MergePackageAssemblyReferences(I
222220
{
223221
if (referenceSets == null)
224222
{
225-
Enumerable.Empty<PackageReferenceSet>();
223+
return Enumerable.Empty<PackageReferenceSet>();
226224
}
227225

228226
var referenceSetGroups = referenceSets.GroupBy(set => set.TargetFramework);
@@ -244,7 +242,7 @@ private static IEnumerable<PackageReferenceSet> MergePackageAssemblyReferences(I
244242

245243
public IEnumerable<PackageType> PackageTypes { get; set; } = new List<PackageType>();
246244

247-
public LicenseMetadata LicenseMetadata { get; set; } = null;
245+
public LicenseMetadata? LicenseMetadata { get; set; } = null;
248246

249247
private static IEnumerable<PackageDependencyGroup> MergeDependencyGroups(IEnumerable<PackageDependencyGroup> actualDependencyGroups)
250248
{
@@ -283,7 +281,7 @@ private static PackageDependencyGroup CreatePackageDependencyGroup(PackageDepend
283281
{
284282
var dependenciesList = dependencyGroup.Packages.Select(dependency =>
285283
new PackageDependency(
286-
dependency.Id.SafeTrim(),
284+
dependency.Id.SafeTrim()!,
287285
dependency.VersionRange,
288286
dependency.Include,
289287
dependency.Exclude)).ToList();
@@ -306,7 +304,7 @@ public IEnumerable<string> Validate()
306304
}
307305
else
308306
{
309-
if (Id.Length > PackageIdValidator.MaxPackageIdLength)
307+
if (Id!.Length > PackageIdValidator.MaxPackageIdLength)
310308
{
311309
yield return String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_IdMaxLengthExceeded);
312310
}
@@ -369,7 +367,7 @@ public IEnumerable<string> Validate()
369367
}
370368
}
371369

372-
if (_licenseUrl != null && LicenseMetadata != null && (string.IsNullOrWhiteSpace(_licenseUrl) || !LicenseUrl.Equals(LicenseMetadata.LicenseUrl)))
370+
if (_licenseUrl != null && LicenseMetadata != null && (string.IsNullOrWhiteSpace(_licenseUrl) || !LicenseUrl!.Equals(LicenseMetadata.LicenseUrl)))
373371
{
374372
yield return NuGetResources.Manifest_LicenseUrlCannotBeUsedWithLicenseMetadata;
375373
}

0 commit comments

Comments
 (0)