Skip to content

Commit 6e6fd4f

Browse files
authored
Merge pull request #174 from AArnott/nrt
Add nullable ref type annotations
2 parents c934af4 + 5fe588c commit 6e6fd4f

File tree

176 files changed

+2029
-2023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+2029
-2023
lines changed

src/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<LangVersion>8</LangVersion>
11+
<Nullable>enable</Nullable>
1112
<NoWarn>CS1591;CS1701</NoWarn>
1213
<UpdateXlfOnBuild Condition=" '$(UpdateXlfOnBuild)' == '' ">true</UpdateXlfOnBuild>
1314

@@ -30,6 +31,7 @@
3031
<PackageReference Include="Nerdbank.GitVersioning" Version="3.2.31" PrivateAssets="all" />
3132
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205" PrivateAssets="all" />
3233
<PackageReference Include="MicroBuild.VisualStudio" Version="$(MicroBuildVersion)" PrivateAssets="all" />
34+
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.7.0" PrivateAssets="all" />
3335
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
3436
</ItemGroup>
3537
<ItemGroup>

src/Microsoft.VisualStudio.Composition.Analyzers/Microsoft.VisualStudio.Composition.Analyzers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ItemGroup>
1616
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" PrivateAssets="all" />
1717
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.8" PrivateAssets="all" />
18+
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
1819
</ItemGroup>
1920

2021
<ItemGroup>

src/Microsoft.VisualStudio.Composition.AppHost/CreateComposition.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public CreateComposition()
7777
/// <summary>
7878
/// Gets or sets a list of codes to suppress warnings for.
7979
/// </summary>
80-
public string[] NoWarn { get; set; }
80+
public string[]? NoWarn { get; set; }
8181

8282
/// <summary>
8383
/// Gets or sets a value indicating whether to continue when errors occur while scanning MEF assemblies.
@@ -92,21 +92,21 @@ public CreateComposition()
9292
public bool ContinueOnCompositionErrors { get; set; }
9393

9494
[Required]
95-
public string CompositionCacheFile { get; set; }
95+
public string CompositionCacheFile { get; set; } = null!;
9696

97-
public string DgmlOutputPath { get; set; }
97+
public string? DgmlOutputPath { get; set; }
9898

9999
/// <summary>
100100
/// Gets or sets the directory to write the discovery and composition log files.
101101
/// </summary>
102102
[Required]
103-
public string LogOutputPath { get; set; }
103+
public string LogOutputPath { get; set; } = null!;
104104

105105
/// <summary>
106106
/// Gets or sets a list of files that were written during this task's execution.
107107
/// </summary>
108108
[Output]
109-
public ITaskItem[] FileWrites { get; set; }
109+
public ITaskItem[]? FileWrites { get; set; }
110110

111111
/// <inheritdoc />
112112
public void Cancel() => this.cts.Cancel();
@@ -171,7 +171,7 @@ public override bool Execute()
171171
if (!string.IsNullOrEmpty(this.DgmlOutputPath))
172172
{
173173
configuration.CreateDgml().Save(this.DgmlOutputPath);
174-
this.writtenFiles.Add(this.DgmlOutputPath);
174+
this.writtenFiles.Add(this.DgmlOutputPath!);
175175
}
176176

177177
this.CancellationToken.ThrowIfCancellationRequested();
@@ -304,13 +304,13 @@ private string GetMEFAssemblyFullPath(ITaskItem taskItem)
304304
return Path.GetFullPath(taskItem.GetMetadata("FullPath"));
305305
}
306306

307-
private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
307+
private Assembly? CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
308308
{
309309
// apply any existing policy
310310
AssemblyName referenceName = new AssemblyName(AppDomain.CurrentDomain.ApplyPolicy(args.Name));
311311

312312
string fileName = referenceName.Name + ".dll";
313-
Assembly assm;
313+
Assembly? assm;
314314

315315
// Look through user-specified assembly lists.
316316
foreach (var candidate in this.catalogAssemblyPaths.Concat(this.ReferenceAssemblies.Select(i => i.GetMetadata("FullPath"))))
@@ -336,7 +336,7 @@ private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs a
336336
}
337337

338338
// look next to requesting assembly
339-
string assemblyPath = args.RequestingAssembly?.Location;
339+
string? assemblyPath = args.RequestingAssembly?.Location;
340340
if (!string.IsNullOrEmpty(assemblyPath))
341341
{
342342
probingPath = Path.Combine(Path.GetDirectoryName(assemblyPath), fileName);
@@ -390,7 +390,7 @@ private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs a
390390
/// <param name="minimumVersion">Minimum version to consider.</param>
391391
/// <param name="assembly">loaded assembly.</param>
392392
/// <returns>true if assembly was loaded.</returns>
393-
private bool Probe(string filePath, Version minimumVersion, out Assembly assembly)
393+
private bool Probe(string filePath, Version minimumVersion, [NotNullWhen(true)] out Assembly? assembly)
394394
{
395395
if (File.Exists(filePath))
396396
{

src/Microsoft.VisualStudio.Composition.AppHost/CreateContainerFactoryBootstrapFile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ namespace Microsoft.VisualStudio.Composition.AppHost
1414
public class CreateContainerFactoryBootstrapFile : Microsoft.Build.Utilities.Task
1515
{
1616
[Required]
17-
public string BootstrapFile { get; set; }
17+
public string BootstrapFile { get; set; } = null!;
1818

1919
[Required]
20-
public string CompositionCacheFile { get; set; }
20+
public string CompositionCacheFile { get; set; } = null!;
2121

2222
[Required]
23-
public string RootNamespace { get; set; }
23+
public string RootNamespace { get; set; } = null!;
2424

2525
public override bool Execute()
2626
{

src/Microsoft.VisualStudio.Composition.AppHost/Microsoft.VisualStudio.Composition.AppHost.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
</ItemGroup>
1717
<ItemGroup>
1818
<PackageReference Include="Nerdbank.MSBuildExtension" Version="0.1.17-beta" PrivateAssets="all" />
19+
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
1920
</ItemGroup>
2021
</Project>

src/Microsoft.VisualStudio.Composition/ArrayRental`1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ internal static class ArrayRental<T>
1515

1616
internal static Rental<T[]> Get(int length)
1717
{
18-
Stack<T[]> stack;
19-
if (!Arrays.Value.TryGetValue(length, out stack))
18+
Stack<T[]>? stack;
19+
if (!Arrays.Value!.TryGetValue(length, out stack))
2020
{
2121
Arrays.Value.Add(length, stack = new Stack<T[]>());
2222
}

src/Microsoft.VisualStudio.Composition/ByValueEquality+AssemblyNameComparer.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ internal AssemblyNameComparer(bool fastCheck = true)
2828
this.fastCheck = fastCheck;
2929
}
3030

31-
public bool Equals(AssemblyName x, AssemblyName y)
31+
public bool Equals(AssemblyName? x, AssemblyName? y)
3232
{
33-
if (x == null ^ y == null)
33+
if (x is null && y is null)
3434
{
35-
return false;
35+
return true;
3636
}
3737

38-
if (x == null)
38+
if (x is null || y is null)
3939
{
40-
return true;
40+
return false;
4141
}
4242

4343
// If fast check is enabled, we can compare the code bases
@@ -51,29 +51,26 @@ public bool Equals(AssemblyName x, AssemblyName y)
5151
// compare the PublicKeys first, but then fall back to GetPublicKeyToken(), which
5252
// will generate a public key token for the AssemblyName that has a public key and
5353
// return the public key token for the other AssemblyName.
54-
byte[] xPublicKey = x.GetPublicKey();
55-
byte[] yPublicKey = y.GetPublicKey();
54+
byte[]? xPublicKey = x.GetPublicKey();
55+
byte[]? yPublicKey = y.GetPublicKey();
5656

5757
// Testing on FullName is horrifically slow.
5858
// So test directly on its components instead.
5959
if (xPublicKey != null && yPublicKey != null)
6060
{
6161
return x.Name == y.Name
62-
&& x.Version.Equals(y.Version)
62+
&& Equals(x.Version, y.Version)
6363
&& string.Equals(x.CultureName, y.CultureName)
6464
&& ByValueEquality.Buffer.Equals(xPublicKey, yPublicKey);
6565
}
6666

6767
return x.Name == y.Name
68-
&& x.Version.Equals(y.Version)
68+
&& Equals(x.Version, y.Version)
6969
&& string.Equals(x.CultureName, y.CultureName)
7070
&& ByValueEquality.Buffer.Equals(x.GetPublicKeyToken(), y.GetPublicKeyToken());
7171
}
7272

73-
public int GetHashCode(AssemblyName obj)
74-
{
75-
return obj.Name.GetHashCode();
76-
}
73+
public int GetHashCode(AssemblyName obj) => obj.Name?.GetHashCode() ?? 0;
7774
}
7875
}
7976
}

src/Microsoft.VisualStudio.Composition/ByValueEquality+BufferComparer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ private BufferComparer()
2020
{
2121
}
2222

23-
public bool Equals(byte[] x, byte[] y)
23+
public bool Equals(byte[]? x, byte[]? y)
2424
{
2525
if (x == y)
2626
{
2727
return true;
2828
}
2929

30-
if (x == null ^ y == null)
30+
if (x is null || y is null)
3131
{
3232
return false;
3333
}

0 commit comments

Comments
 (0)